This class provides main memory access to attribute values and text contents. @author BaseX Team, BSD License @author Christian Gruen
| 21 | * @author Christian Gruen |
| 22 | */ |
| 23 | public final class MemValues extends ValueIndex { |
| 24 | /** Values. */ |
| 25 | private final TokenSet values; |
| 26 | /** IDs lists. */ |
| 27 | private ArrayList<int[]> idsList; |
| 28 | /** ID array lengths. */ |
| 29 | private IntList lenList; |
| 30 | /** Order flags. */ |
| 31 | private BoolList reorder; |
| 32 | |
| 33 | /** |
| 34 | * Constructor. |
| 35 | * @param data data instance |
| 36 | * @param type index type |
| 37 | */ |
| 38 | public MemValues(final Data data, final IndexType type) { |
| 39 | super(data, type); |
| 40 | // token index: work extra token set instance |
| 41 | values = type == IndexType.TOKEN ? new TokenSet() : |
| 42 | ((MemData) data).values(type == IndexType.TEXT); |
| 43 | final int s = values.size() + 1; |
| 44 | idsList = new ArrayList<>(s); |
| 45 | lenList = new IntList(s); |
| 46 | reorder = new BoolList(s); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public IndexIterator iter(final IndexSearch search) { |
| 51 | final int id = values.index(search.token()); |
| 52 | if(id == 0) return IndexIterator.EMPTY; |
| 53 | |
| 54 | final int len = lenList.get(id); |
| 55 | final int[] ids = idsList.get(id), pres; |
| 56 | if(data.meta.updindex) { |
| 57 | final IntList tmp = new IntList(); |
| 58 | for(int i = 0; i < len; ++i) tmp.add(data.pre(ids[i])); |
| 59 | pres = tmp.sort().finish(); |
| 60 | } else { |
| 61 | pres = ids; |
| 62 | } |
| 63 | |
| 64 | return new IndexIterator() { |
| 65 | int p; |
| 66 | @Override |
| 67 | public boolean more() { return p < len; } |
| 68 | @Override |
| 69 | public int pre() { return pres[p++]; } |
| 70 | @Override |
| 71 | public int size() { return len; } |
| 72 | }; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public IndexCosts costs(final IndexSearch search) { |
| 77 | return IndexCosts.get(lenList.get(values.index(search.token()))); |
| 78 | } |
| 79 | |
| 80 | @Override |
nothing calls this directly
no outgoing calls
no test coverage detected