1 package net.obsearch.index;
2 import net.obsearch.asserts.OBAsserts;
3 import net.obsearch.ob.OBInt;
4 import java.util.Arrays;
5 import net.obsearch.exception.OBException;
6 /*
7 OBSearch: a distributed similarity search engine This project is to
8 similarity search what 'bit-torrent' is to downloads.
9 Copyright (C) 2009 Arnoldo Jose Muller Molina
10
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25 /**
26 * Commons
27 *
28 * @author Arnoldo Jose Muller Molina
29 */
30
31
32 public class CommonsInt{
33
34 /**
35 * This method returns a list of all the distances of the query against the DB.
36 * This helps to calculate EP values in a cheaper way. results that are equal to the original object are added
37 * as Integer.MAX_VALUE
38 * @param query
39 * @param filterSame if True we do not return objects o such that query.equals(o)
40 * @return
41 * @throws OBException
42 * @throws InstantiationException
43 * @throws IllegalAccessException
44 */
45 public static int[] fullMatchLite(OBInt query, boolean filterSame, IndexInt index) throws OBException, IllegalAccessException, InstantiationException{
46 long max = index.databaseSize();
47 OBAsserts.chkAssert(max < Integer.MAX_VALUE, "Cannot exceed 2^32");
48 int[] result = new int[(int)max];
49 int id = 0;
50 OBInt o = (OBInt)index.getType().newInstance();
51 while(id < max){
52 index.loadObject(id, o);
53 int distance = o.distance(query);
54 if(distance == 0 && o.equals(query) && filterSame){
55 result[id] = Integer.MAX_VALUE;
56 }else{
57 result[id] = distance;
58 }
59 id++;
60 }
61
62 Arrays.sort(result);
63 return result;
64 }
65
66 }
67
68
69
70