Brian,
I think you can use D3 indexes for your application, you just have to be
a little careful.
Since the null items are the problem, create an index without any null
items by concatenating the key to the value to create a unique field to
index on (as Ross suggested). In this case, if the field you actually
want to index is <16>, then
1. create a dict item to index on, e.g.
uniq16
1 s
2 16
....
8 a16:"-":0
9 l
10 10
2. build the index
create-index myfile uniq16
3. select from tcl for <16> = "abc"
select myfile with uniq16 eq "abc-]"
4. select from basic (not tested!)
root myfile,'a16:"-":0' to root.myfile else ....
result = ""
thing = "abc-"
search = thing
len = len(thing)
loop
key("x",root.myfile,search,id) then
if search[1,len] ne thing then done = 1
end else
done = 1
end
until done do
result<-1> = id
repeat
Speaking of basic btree selects... here is a generic btree lookup
subroutine that I use (because I can't remember the root and key syntax):
0001 subroutine get.btree(thing,result,filename,fieldname)
0002 * Get result id(s) from the btree index fieldname for filename.
0003 * Result is mv if more than 1 id found for thing.
0004 * If thing ends with ] then return all starting with thing.
0005 * If thing doesn't end with ] then return all exactly matching thing.
0006 * If thing requires an iconv (e.g. a date) then iconv before
passing it.
0007
0008 begin case
0009 case fieldname matches "'a'0n"
0010 ac = fieldname
0011 case fieldname matches "0n"
0012 ac = "a":fieldname
0013 case 1
0014 open "dict",filename to dict.filevar else
0015 sleep 1
0016 open "dict",filename to dict.filevar else
0017 stop 201,"dict ":filename
0018 end
0019 end
0020 read rec from dict.filevar,fieldname then
0021 if rec<8>[1,1] eq "A" then
0022 ac = rec<8>
0023 end else
0024 ac = "A":rec<2>
0025 end
0026 end else
0027 print " error! can't read item ":fieldname:" in dict ":filename
0028 stop
0029 end
0030 end case
0031
0032 root filename,ac to fileroot else
0033 sleep 1 ;* pause & try again for remote files
0034 root filename,ac to fileroot else
0035 print "error! no index defined for ":filename:",":ac:"
(":fieldname:")
0036 stop
0037 end
0038 end
0039
0040 lent = len(thing)
0041 if thing[lent,1] eq "]" then
0042 wildcard = 1
0043 lent -= 1
0044 thing = thing[1,lent]
0045 end else
0046 wildcard = 0
0047 end
0048
0049 search = thing
0050 result = ""
0051 id = ""
0052 done = 0
0053
0054 loop
0055 key("x",fileroot,search,id) then
0056 if wildcard then
0057 if search[1,lent] ne thing then done = 1
0058 end else
0059 if search ne thing then done = 1
0060 end
0061 end else
0062 done = 1
0063 end
0064 until done do
0065 result<-1> = id
0066 repeat
0067
0068 convert @am to @vm in result
0069
0070 return
/Scott Ballinger
Pareto Corporation
Edmonds WA USA
206 713 6006
Brian Bond wrote:
Quote:
It just seems really odd that a D3 index cannot actually be used in cases
where an index might come in handy.
'nuff said. |