MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / insert

Method insert

JSAT/src/jsat/linear/vectorcollection/VPTree.java:191–225  ·  view source on GitHub ↗
(V x)

Source from the content-addressed store, hash-verified

189 }
190
191 @Override
192 public void insert(V x)
193 {
194 int indx = size++;
195 allVecs.add(x);
196 if(distCache != null)
197 distCache.addAll(dm.getQueryInfo(x));
198
199
200 if(root == null)
201 {
202 ArrayList<Pair<Double, Integer>> list = new ArrayList<Pair<Double, Integer>>();
203 list.add(new Pair<Double, Integer>(Double.MAX_VALUE, indx));
204 root = new VPLeaf(list);
205 return;
206 }
207 ///else, do a normal insert
208 root.insert(indx, Double.MAX_VALUE);
209 if(root instanceof jsat.linear.vectorcollection.VPTree.VPLeaf)//is root a leaf?
210 {
211 VPLeaf leaf = (VPLeaf) root;
212 if(leaf.points.size() > maxLeafSize*maxLeafSize)//check to expand
213 {
214 //hacky, but works
215 int orig_leaf_isze = maxLeafSize;
216 maxLeafSize = maxLeafSize*maxLeafSize;//call normal construct with adjusted leaf size to stop expansion
217 ArrayList<Pair<Double, Integer>> S = new ArrayList<Pair<Double, Integer>>();
218 for(int i = 0; i < leaf.points.size(); i++)
219 S.add(new Pair<Double, Integer>(Double.MAX_VALUE, leaf.points.getI(i)));
220 root = makeVPTree(S);
221 maxLeafSize = orig_leaf_isze;//restor
222 }
223 }
224 //else, normal non-leaf root insert handles expansion when needed
225 }
226
227 @Override
228 @SuppressWarnings("unchecked")

Callers 1

Calls 7

makeVPTreeMethod · 0.95
getIMethod · 0.80
getQueryInfoMethod · 0.65
insertMethod · 0.65
sizeMethod · 0.65
addMethod · 0.45
addAllMethod · 0.45

Tested by 1