I did it
- Posted by Alan Tu <ATU5713 at COMPUSERVE.COM> Dec 06, 1998
- 451 views
I am designing a specialized database application for a fantasy basketball league. I import the formatted-file line-by-line and store the stats as a sequence. I built and printed to a file an index: {lastname,firstname,index of record in database} I built a search function that returned the index of the record in the main database. I'm submitting this for your improvement and for anyone's reference. include get.e integer datfile, idxfile sequence db, index datfile = open("fbk.dat","rb") db = get(datfile) db = db[2] close(datfile) idxfile = open("fbk.idx","rb") index = get(idxfile) index = index[2] close(idxfile) type record(integer x) return x >= 1 and x <= length(db) end type function search(sequence lastname, sequence firstname) sequence hit, temp record rec integer comp hit = {{},{},{}} temp = index while compare(hit[1..2],{lastname,firstname}) != 0 do rec = floor(length(temp)/2) hit = temp[rec] comp = compare(hit[1..2],{lastname,firstname}) if comp = -1 then temp = temp[rec+1..length(temp)] elsif comp = 1 then temp = temp[1..rec-1] end if end while return temp[rec][3] end function Alan