Re: Searching for Data in EDS
- Posted by irv at take.maxleft.com Nov 11, 2002
- 441 views
On Monday 11 November 2002 03:27 pm, you wrote: > > > From: C. K. Lester [mailto:cklester at yahoo.com] > > > > Let's say I have records set up like this: > > > > key: X, data: Y > > > > where X and Y are integers (atoms). > > > > How would I find all records with Y = 2? > > > > Do I just have to loop through all the records? What if I > > have a million > > records?! > > > > Elsewhere, anybody already have good code for managing EDS > > files to handle > > cases like this (a function that returns a sequence with the > > record numbers > > of all records where Y = 2)...? > > Your best bet is to use indices (there was a fairly in depth treatment on > this topic previously--I believe the question was regarding record albums, > and I think Irv was the main responder), where you keep a separate > table/record to remember all the keys which have certain properties. If you are likely to have duplicate Y values, then you might save lookup time by creating a unique value index. For example, given the following records: key val 1 99 2 102 3 99 4 25 5 99 You can build an index like this: key val 25 {4} 99 {1,3,5} 102 {2} So looking up a given value in the index is very fast (binary lookup?) and then looking up the individual records which contain that value is simply a matter of iterating thru the short list. Whether this is really practical depend on how many of your values are actual dupes, how often the database is updated, and whether there is a lot of extra data that goes with each record. Regards, Irv