[Purdue-pm] fast table lookup of randomly associated items
Rick Westerman
westerman at purdue.edu
Wed May 19 12:41:42 PDT 2010
----- Original Message -----
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Say I have a table like the following:
>
> number Item
> 1-5 A
> 6 B
> 7-12 C
> 13-20 D
> 21-25 E
> 26-30 F
>
> Say I then have a random number generator that spits out a number from
> 1-30.
>
> What is the fastest way to look up the item associated with that
> random number?
Fastest? I'd say a simple array lookup. Could be quite memory intensive but, at least in 'C' and I presume Perl, array lookups are simple pointer additions. Can't be any faster than that as long as you do not exceed physical memory boundries.
>
> For more fun, say I want to store that table in a text file what is a
> good way to represent that?
I sort of liked your human readable format above. JSON is fine but not as clear to the lay person.
All-in-all could be a good challenge problem.
--
Rick Westerman
westerman at purdue.edu
Bioinformatics specialist at the Genomics Facility.
Phone: (765) 494-0505 FAX: (765) 496-7255
Department of Horticulture and Landscape Architecture
625 Agriculture Mall Drive
West Lafayette, IN 47907-2010
Physically located in room S049, WSLR building
More information about the Purdue-pm
mailing list