Re: how to efficiently find line number k
From: James Dennett (jdennett_at_acm.org)
Date: 09/29/04
- Next message: Francis Glassborow: "Re: how to efficiently find line number k"
- Previous message: James Dennett: "Re: Why is C still being used instead of C++"
- Next in thread: Francis Glassborow: "Re: how to efficiently find line number k"
- Maybe reply: Francis Glassborow: "Re: how to efficiently find line number k"
- Reply: Alwyn: "Re: how to efficiently find line number k"
- Maybe reply: Thomas Matthews: "Re: how to efficiently find line number k"
- Maybe reply: Mark P: "Re: how to efficiently find line number k"
- Maybe reply: Karl Heinz Buchegger: "Re: how to efficiently find line number k"
- Maybe reply: Karl Heinz Buchegger: "Re: how to efficiently find line number k"
- Maybe reply: Francis Glassborow: "Re: how to efficiently find line number k"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 28 Sep 2004 21:13:01 -0700
b83503104 wrote:
> I have a big text file with millions of lines, and given any number k
> as input, I want to output line k. What is the most efficient way to
> do this, other than checking end-of-line k times?
In general there's no more efficient way possible. You could
cache that information (i.e., build an index) or use a format
with fixed-size records, or various combinations, but there's
no magical way to quickly get to line 500000 of a text file
without reading the previous 499999 lines.
For some platforms, that may not be the case; some filesystems
are inherently record-oriented, and C or C++ implementations
targetting such filesystems may well offer extensions to do
record based random access. That's not true of any platform
on which I've worked though; modern OS's would tend to push
that kind of functionality off to a database application.
-- James
- Next message: Francis Glassborow: "Re: how to efficiently find line number k"
- Previous message: James Dennett: "Re: Why is C still being used instead of C++"
- Next in thread: Francis Glassborow: "Re: how to efficiently find line number k"
- Maybe reply: Francis Glassborow: "Re: how to efficiently find line number k"
- Reply: Alwyn: "Re: how to efficiently find line number k"
- Maybe reply: Thomas Matthews: "Re: how to efficiently find line number k"
- Maybe reply: Mark P: "Re: how to efficiently find line number k"
- Maybe reply: Karl Heinz Buchegger: "Re: how to efficiently find line number k"
- Maybe reply: Karl Heinz Buchegger: "Re: how to efficiently find line number k"
- Maybe reply: Francis Glassborow: "Re: how to efficiently find line number k"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|