(List<V> list, DistanceMetric dm, VPSelection vpSelection, Random rand, int sampleSize, int searchIterations, ExecutorService threadpool)
| 67 | } |
| 68 | |
| 69 | public VPTree(List<V> list, DistanceMetric dm, VPSelection vpSelection, Random rand, int sampleSize, int searchIterations, ExecutorService threadpool) |
| 70 | { |
| 71 | this.dm = dm; |
| 72 | if(!dm.isSubadditive()) |
| 73 | throw new RuntimeException("VPTree only supports metrics that support the triangle inequality"); |
| 74 | this.rand = rand; |
| 75 | this.sampleSize = sampleSize; |
| 76 | this.searchIterations = searchIterations; |
| 77 | this.size = list.size(); |
| 78 | this.vpSelection = vpSelection; |
| 79 | this.allVecs = list; |
| 80 | if(threadpool == null || threadpool instanceof FakeExecutor) |
| 81 | distCache = dm.getAccelerationCache(allVecs); |
| 82 | else |
| 83 | distCache = dm.getAccelerationCache(allVecs, threadpool); |
| 84 | //Use simple list so both halves can be modified simultaniously |
| 85 | List<Pair<Double, Integer>> tmpList = new SimpleList<Pair<Double, Integer>>(list.size()); |
| 86 | for(int i = 0; i < allVecs.size(); i++) |
| 87 | tmpList.add(new Pair<Double, Integer>(-1.0, i)); |
| 88 | if(threadpool == null) |
| 89 | this.root = makeVPTree(tmpList); |
| 90 | else |
| 91 | { |
| 92 | ModifiableCountDownLatch mcdl = new ModifiableCountDownLatch(1); |
| 93 | this.root = makeVPTree(tmpList, threadpool, mcdl); |
| 94 | mcdl.countDown(); |
| 95 | try |
| 96 | { |
| 97 | mcdl.await(); |
| 98 | } |
| 99 | catch (InterruptedException ex) |
| 100 | { |
| 101 | Logger.getLogger(VPTree.class.getName()).log(Level.SEVERE, null, ex); |
| 102 | System.err.println("Falling back to single threaded VPTree constructor"); |
| 103 | tmpList.clear(); |
| 104 | for(int i = 0; i < list.size(); i++) |
| 105 | tmpList.add(new Pair<Double, Integer>(-1.0, i)); |
| 106 | this.root = makeVPTree(tmpList); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | public VPTree(List<V> list, DistanceMetric dm, VPSelection vpSelection, Random rand, int sampleSize, int searchIterations) |
| 112 | { |
nothing calls this directly
no test coverage detected