Skip to content

Commit fb5ee85

Browse files
committed
indexer optimize
1 parent 3e567f8 commit fb5ee85

File tree

2 files changed

+18
-34
lines changed

2 files changed

+18
-34
lines changed

SpatialIndex_Indexer.xml

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<TimeCreated>63812,81607.191685</TimeCreated>
66

77
<Parameter name="NODESIZE">
8-
<Default>4</Default>
8+
<Default>100</Default>
99
</Parameter>
1010

1111
<Parameter name="ROOTNODE">
@@ -51,18 +51,17 @@
5151
</Method>
5252

5353
<Method name="Insert">
54-
<FormalSpec>x:%Float,y:%Float,id:%String,data:%String="",block:%String=..#ROOTNODE</FormalSpec>
54+
<FormalSpec>x:%Float,y:%Float,id:%String,data:%String="",block:%String=..#ROOTNODE,node:IndexNode=""</FormalSpec>
5555
<Implementation><![CDATA[
56-
#dim node As IndexNode
57-
set node = ##class(IndexNode).Get(..indexGlobal, block)
58-
if ('..IsInside(x, y, block)) return
56+
set:node="" node = ##class(IndexNode).Get(..indexGlobal, block)
57+
if ('..IsInside(x, y, node)) return
5958
if (node.isLeaf){
60-
if ('..Contains(x, y, block)) {
59+
if ('..LeafContains(x, y, block)) {
6160
set node.size = node.size + 1
6261
do ##class(IndexNode).Put(..indexGlobal, block, node)
6362
}
6463
set @..indexGlobal@(block, "data", x, y, id) = data
65-
if (node.size > ..#NODESIZE) do ..Split(block)
64+
if (node.size > ..#NODESIZE) do ..Split(block, node)
6665
}
6766
else{
6867
for i=0:1:3 {
@@ -77,14 +76,14 @@
7776
<Implementation><![CDATA[
7877
#dim node As IndexNode
7978
set node = ##class(IndexNode).Get(..indexGlobal, block)
80-
if ('..IsInside(x, y, block)) return
79+
if ('..IsInside(x, y, node)) return
8180
if (node.isLeaf){
82-
if ('..Contains(x, y, block)) {
81+
if ('..LeafContains(x, y, block)) {
8382
//TODO: throw error
8483
return
8584
}
8685
kill @..indexGlobal@(block, "data", x, y, id)
87-
if ('..Contains(x, y, block)){
86+
if ('..LeafContains(x, y, block)){
8887
set node.size=node.size-1
8988
do ##class(IndexNode).Put(..indexGlobal, block, node)
9089
}
@@ -99,37 +98,22 @@
9998
</Method>
10099

101100
<Method name="IsInside">
102-
<FormalSpec>x:%Float,y:%Float,block:%String</FormalSpec>
101+
<FormalSpec>x:%Float,y:%Float,node:IndexNode</FormalSpec>
103102
<ReturnType>%Boolean</ReturnType>
104-
<Implementation><![CDATA[
105-
#dim node As IndexNode
106-
set node = ##class(IndexNode).Get(..indexGlobal, block)
107-
return (x>=node.minX) && (x<node.maxX) && (y>=node.minY) && (y<node.maxY)
103+
<Implementation><![CDATA[return (x>=node.minX) && (x<node.maxX) && (y>=node.minY) && (y<node.maxY)
108104
]]></Implementation>
109105
</Method>
110106

111-
<Method name="Contains">
112-
<FormalSpec>x:%Float,y:%Float,block:%String=..#ROOTNODE</FormalSpec>
107+
<Method name="LeafContains">
108+
<FormalSpec>x:%Float,y:%Float,block:%String</FormalSpec>
113109
<ReturnType>%Boolean</ReturnType>
114-
<Implementation><![CDATA[
115-
#dim node As IndexNode
116-
set node = ##class(IndexNode).Get(..indexGlobal, block)
117-
if ('..IsInside(x, y, block)) return $$$NO
118-
if (node.isLeaf){
119-
return $DATA(@..indexGlobal@(block, "data", x, y))>0
120-
}
121-
for i=0:1:3 {
122-
if (..Contains(x, y, block_i)) return $$$YES
123-
}
124-
return $$$NO
110+
<Implementation><![CDATA[return $DATA(@..indexGlobal@(block, "data", x, y))>0
125111
]]></Implementation>
126112
</Method>
127113

128114
<Method name="Split">
129-
<FormalSpec>block:%String</FormalSpec>
115+
<FormalSpec>block:%String,node:IndexNode</FormalSpec>
130116
<Implementation><![CDATA[
131-
#dim node As IndexNode
132-
set node = ##class(IndexNode).Get(..indexGlobal, block)
133117
set midX = (node.minX+node.maxX)/2
134118
set midY = (node.minY+node.maxY)/2
135119
@@ -154,7 +138,7 @@
154138
while (y'=""){
155139
set id = $o(@..indexGlobal@(block, "data", x, y, ""))
156140
while (id'=""){
157-
do ..Insert(x, y, id, @..indexGlobal@(block, "data", x, y, id), block)
141+
do ..Insert(x, y, id, @..indexGlobal@(block, "data", x, y, id), block, node)
158142
set id = $o(@..indexGlobal@(block, "data", x, y, id))
159143
}
160144
set y = $o(@..indexGlobal@(block, "data", x, y))

SpatialIndex_Test.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
<Method name="load">
2626
<ClassMethod>1</ClassMethod>
27-
<FormalSpec>filename:%String="c:\temp\RUcut.txt"</FormalSpec>
27+
<FormalSpec>filename:%String="c:\temp\RUcut.txt",maxline:%Integer=1000000</FormalSpec>
2828
<Implementation><![CDATA[
2929
do ..%KillExtent()
3030
do $system.Process.SetZEOF(1)
@@ -33,7 +33,7 @@
3333
write "cannot open ", filename,!
3434
quit
3535
}
36-
for {
36+
for i=1:1:maxline{
3737
use filename read line
3838
quit:$ZEOF=-1
3939
set columnList = $ListFromString(line," ")

0 commit comments

Comments
 (0)