public void setUp(short pageSize, IndexFactory<Long, Integer> indexType) throws IOException { File path = File.createTempFile("test-mixed", ".tmp", new File("test")); path.delete(); System.out.println("file: " + path); m_pageSize = pageSize; m_dataSize = (short) (pageSize - (MAGIC.length + Long.SIZE / 8)); m_pageFile = createFileFactory(path, pageSize); m_indexFactory = indexType; // create the index Transaction tx = m_pageFile.tx(); try { Index<Long, Integer> index = m_indexFactory.create(tx); // seed the index with some metadata about the test index.put(-2L, (int) m_pageSize); index.put(-3L, (int) m_dataSize); index.put(-4L, MAGIC.length); } finally { tx.commit(); } m_pageFile.flush(); }
Class128(Class353 class353, int i, Index class302) { index22 = class302; if (index22 != null) { int i_22_ = index22.method3526(-20871) - 1; index22.method3537(-2, i_22_); } }
@Override protected View openIndex(String name) throws Exception { Index ix = mDb.openIndex(name); View view = ix.viewTransformed(new BasicTransform()); mViews.put(view, ix); return view; }
/** * This assumes each line is of the form (number=value) and it adds each value in order of the * lines in the file * * @param file Which file to load * @return An index built out of the lines in the file */ public static Index<String> loadFromFilename(String file) { Index<String> index = new HashIndex<String>(); BufferedReader br = null; try { br = new BufferedReader(new FileReader(file)); for (String line; (line = br.readLine()) != null; ) { int start = line.indexOf('='); if (start == -1 || start == line.length() - 1) { continue; } index.add(line.substring(start + 1)); } br.close(); } catch (Exception e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException ioe) { // forget it } } } return index; }
/* Allgemeine Methode für Einzelspalten-Index */ private void createSingleIndex(Statement st, Index... indizes) throws SQLException { for (Index i : indizes) { String sql_start = ""; String sql_table = ""; String sql_end = ""; /* index == false? Dann lösche vorhandenen Index */ if (!i.isIndexed()) { sql_start = "DROP INDEX idx_" + i.getIndexField() + " IF EXISTS"; st.execute(sql_start); /* Ansonsten erstelle einen, abhängig von der Klasse und den Feldern */ } else { sql_start = "CREATE INDEX idx_" + i.getIndexField() + " ON "; sql_end = "(" + i.getIndexField() + ")"; if (i.getIndexClass().equals(Kunde.class)) { sql_table = "Kunde"; } else if (i.getIndexClass().equals(Anruf.class)) { sql_table = "Anruf"; if (i.getIndexField().equals("anrufer") || i.getIndexField().equals("angerufener")) { sql_end = "(id_" + i.getIndexField() + ")"; } } else { throw new RuntimeException("TODO"); } st.execute(sql_start + sql_table + sql_end); } } }
@Test public void testSingleLongFieldIndex() throws Exception { final String INDEX_NAME = "singleLongField"; IndexManager indexManager = new IndexManager(TEST_UTIL.getConfiguration()); IndexDefinition indexDef = new IndexDefinition(INDEX_NAME, INDEX_NAME); indexDef.addLongField("field1"); indexManager.createIndex(indexDef); Index index = indexManager.getIndex(INDEX_NAME, INDEX_NAME); long values[] = {Long.MIN_VALUE, -1, 0, 1, Long.MAX_VALUE}; for (long value : values) { IndexEntry entry = new IndexEntry(); entry.addField("field1", value); index.addEntry(entry, Bytes.toBytes("key" + value)); } Query query = new Query(); query.setRangeCondition("field1", Long.MIN_VALUE, Long.MAX_VALUE); QueryResult result = index.performQuery(query); for (long value : values) { assertEquals("key" + value, Bytes.toString(result.next())); } assertNull(result.next()); }
@Override public boolean equals(Object o) { if (o instanceof FastIndex) { FastIndex comp = (FastIndex) o; if (nonZeroEntries != comp.nonZeroEntries) { return false; } else { return Arrays.equals(entryNums, comp.entryNums) && Arrays.equals(entryVals, comp.entryVals); } } else if (o instanceof Index) { Index comp = (Index) o; if (nonZeroEntries() != comp.nonZeroEntries()) { return false; } else { for (int i = 0; i < nonZeroEntries; i++) { if (entryVals[i] != comp.get(entryNums[i])) { return false; } } return true; } } return false; }
public void readByte2Short() throws Exception { Variable t2 = null; assert (null != (t2 = ncfileRead.findVariable("t2"))); assert (t2.getDataType() == DataType.BYTE); Attribute att = t2.findAttribute(CDM.SCALE_FACTOR); assert (null != att); assert (!att.isArray()); assert (1 == att.getLength()); assert (2 == att.getNumericValue().doubleValue()); assert (DataType.SHORT == att.getDataType()); assert (null != (t2 = dsRead.findVariable("t2"))); assert t2 instanceof VariableEnhanced; VariableDS vs = (VariableDS) t2; assert (vs.getDataType() == DataType.SHORT) : vs.getDataType(); assert (!vs.hasMissing()); Array A = vs.read(); assert (A.getElementType() == short.class) : A.getElementType(); Index ima = A.getIndex(); int[] shape = A.getShape(); int i, j; for (i = 0; i < shape[0]; i++) { for (j = 0; j < shape[1]; j++) { assert (A.getShort(ima.set(i, j)) == (2 * (i * 10 + j) + 77)); } } System.out.println("**************TestStandardVar readByte2Short"); }
@Test public void testData() throws Exception { final String INDEX_NAME = "dataIndex"; IndexManager indexManager = new IndexManager(TEST_UTIL.getConfiguration()); IndexDefinition indexDef = new IndexDefinition(INDEX_NAME, INDEX_NAME); indexDef.addStringField("field1"); indexManager.createIndex(indexDef); Index index = indexManager.getIndex(INDEX_NAME, INDEX_NAME); String[] values = new String[] {"foo", "bar"}; for (String value : values) { IndexEntry entry = new IndexEntry(); entry.addField("field1", value); entry.addData(Bytes.toBytes("originalValue"), Bytes.toBytes(value)); index.addEntry(entry, Bytes.toBytes(value)); } Query query = new Query(); query.setRangeCondition("field1", Query.MIN_VALUE, Query.MAX_VALUE); QueryResult result = index.performQuery(query); assertNotNull(result.next()); assertEquals("bar", result.getDataAsString("originalValue")); assertNotNull(result.next()); assertEquals("foo", result.getDataAsString("originalValue")); }
@Test public void testSingleDateTimeFieldIndex() throws Exception { final String INDEX_NAME = "singleDateTimeField"; IndexManager indexManager = new IndexManager(TEST_UTIL.getConfiguration()); IndexDefinition indexDef = new IndexDefinition(INDEX_NAME, INDEX_NAME); DateTimeIndexFieldDefinition fieldDef = indexDef.addDateTimeField("field1"); fieldDef.setPrecision(DateTimeIndexFieldDefinition.Precision.DATETIME_NOMILLIS); indexManager.createIndex(indexDef); Index index = indexManager.getIndex(INDEX_NAME, INDEX_NAME); Date[] values = { new GregorianCalendar(2010, 1, 15, 14, 5, 0).getTime(), new GregorianCalendar(2010, 1, 15, 14, 5, 1).getTime(), new GregorianCalendar(2010, 1, 16, 10, 0, 0).getTime(), new GregorianCalendar(2010, 1, 17, 10, 0, 0).getTime() }; for (int i = 0; i < values.length; i++) { IndexEntry entry = new IndexEntry(); entry.addField("field1", values[i]); index.addEntry(entry, Bytes.toBytes("key" + i)); } Query query = new Query(); query.setRangeCondition( "field1", new GregorianCalendar(2010, 1, 15, 14, 5, 0).getTime(), new GregorianCalendar(2010, 1, 15, 14, 5, 1).getTime()); QueryResult result = index.performQuery(query); assertResultIds(result, "key0", "key1"); }
@Test public void testSingleByteFieldIndex() throws Exception { final String INDEX_NAME = "singleByteField"; IndexManager indexManager = new IndexManager(TEST_UTIL.getConfiguration()); IndexDefinition indexDef = new IndexDefinition(INDEX_NAME, INDEX_NAME); ByteIndexFieldDefinition fieldDef = indexDef.addByteField("field1"); fieldDef.setLength(3); indexManager.createIndex(indexDef); Index index = indexManager.getIndex(INDEX_NAME, INDEX_NAME); // Create a few index entries, inserting them in non-sorted order byte[][] values = {Bytes.toBytes("aaa"), Bytes.toBytes("aab")}; for (int i = 0; i < values.length; i++) { IndexEntry entry = new IndexEntry(); entry.addField("field1", values[i]); index.addEntry(entry, Bytes.toBytes("key" + i)); } Query query = new Query(); query.setRangeCondition("field1", Bytes.toBytes("aaa"), Bytes.toBytes("aab")); QueryResult result = index.performQuery(query); assertResultIds(result, "key0", "key1"); }
@Test public void testDescendingIntAscendingKeyIndex() throws Exception { final String INDEX_NAME = "descendingIntAscendingKey"; IndexManager indexManager = new IndexManager(TEST_UTIL.getConfiguration()); IndexDefinition indexDef = new IndexDefinition(INDEX_NAME, INDEX_NAME); IntegerIndexFieldDefinition fieldDef = indexDef.addIntegerField("field1"); fieldDef.setOrder(Order.DESCENDING); indexManager.createIndex(indexDef); Index index = indexManager.getIndex(INDEX_NAME, INDEX_NAME); Integer[] values = {1, 1, 2, 2}; for (int i = 0; i < values.length; i++) { IndexEntry entry = new IndexEntry(); entry.addField("field1", values[i]); index.addEntry(entry, Bytes.toBytes("key" + (i + 1))); } // The index on the value is descending, the identifiers themselves are ascending! Query query = new Query(); query.setRangeCondition("field1", 2, 1); QueryResult result = index.performQuery(query); assertResultIds(result, "key3", "key4", "key1", "key2"); }
@Test public void testDuplicateValuesIndex() throws Exception { final String INDEX_NAME = "duplicateValues"; IndexManager indexManager = new IndexManager(TEST_UTIL.getConfiguration()); IndexDefinition indexDef = new IndexDefinition(INDEX_NAME, INDEX_NAME); indexDef.addStringField("field1"); indexManager.createIndex(indexDef); Index index = indexManager.getIndex(INDEX_NAME, INDEX_NAME); // Create a few index entries, inserting them in non-sorted order String[] values = {"a", "a", "a", "a", "b", "c", "d"}; for (int i = 0; i < values.length; i++) { IndexEntry entry = new IndexEntry(); entry.addField("field1", values[i]); index.addEntry(entry, Bytes.toBytes("key" + i)); } Query query = new Query(); query.addEqualsCondition("field1", "a"); QueryResult result = index.performQuery(query); assertResultSize(4, result); }
@Test public void testStringPrefixQuery() throws Exception { final String INDEX_NAME = "stringPrefixQuery"; IndexManager indexManager = new IndexManager(TEST_UTIL.getConfiguration()); IndexDefinition indexDef = new IndexDefinition(INDEX_NAME, INDEX_NAME); indexDef.addStringField("field1"); indexManager.createIndex(indexDef); Index index = indexManager.getIndex(INDEX_NAME, INDEX_NAME); String[] values = {"baard", "boer", "beek", "kanaal", "paard"}; for (int i = 0; i < values.length; i++) { IndexEntry entry = new IndexEntry(); entry.addField("field1", values[i]); index.addEntry(entry, Bytes.toBytes("key" + i)); } Query query = new Query(); query.setRangeCondition("field1", "b", "b"); QueryResult result = index.performQuery(query); assertResultIds(result, "key0", "key2", "key1"); }
/** * This takes a Map of keys and business object entries and indexes all indexes attributes in one * method call. * * @param entries */ public void indexAll(Map<RK, A> entries) { if (entries.size() > 0) { try { Map<String, Map<RK, String>> fentries = new HashMap<String, Map<RK, String>>(); for (Field f : indexedFields) { Map<RK, String> m = new HashMap<RK, String>(); fentries.put(f.getName(), m); } for (Map.Entry<RK, A> e : entries.entrySet()) { A bo = e.getValue(); RK key = e.getKey(); for (Field f : indexedFields) { String value = (String) f.get(bo); Map<RK, String> m = fentries.get(f.getName()); m.put(key, value); } } for (Field f : indexedFields) { Map<RK, String> m = fentries.get(f.getName()); Index<A, RK> index = getIndex(f.getName()); index.insert(m); } } catch (IllegalAccessException e) { throw new ObjectGridRuntimeException(e); } } }
@Test public void testSingleDecimalFieldIndex() throws Exception { final String INDEX_NAME = "singleDecimalField"; IndexManager indexManager = new IndexManager(TEST_UTIL.getConfiguration()); IndexDefinition indexDef = new IndexDefinition(INDEX_NAME, INDEX_NAME); indexDef.addDecimalField("field1"); indexManager.createIndex(indexDef); Index index = indexManager.getIndex(INDEX_NAME, INDEX_NAME); String[] values = {"33.66", "-1", "-3.00007E77"}; for (int i = 0; i < values.length; i++) { IndexEntry entry = new IndexEntry(); entry.addField("field1", new BigDecimal(values[i])); index.addEntry(entry, Bytes.toBytes("key" + i)); } { Query query = new Query(); query.setRangeCondition("field1", new BigDecimal(values[2]), new BigDecimal(values[0])); QueryResult result = index.performQuery(query); assertResultIds(result, "key2", "key1", "key0"); } { Query query = new Query(); query.addEqualsCondition("field1", new BigDecimal(values[2])); QueryResult result = index.performQuery(query); assertResultIds(result, "key2"); } }
@Override public boolean dropIndex(final IndexType type) { // close and drop index (return true if no index exists) final Index index = index(type); close(type); return index == null || index.drop(); }
private static void index(Index index, IndexWriter indexWriter) throws IOException { if (index.docs().size() > 1) { indexWriter.addDocuments(index.docs()); } else { indexWriter.addDocument(index.docs().get(0)); } }
public String addAttachment(SqlField field, Entity type) { // Adding normal column index addColumnIndex(field.getField().getName(), type, index.next()); // incrementing the index for the columns ATT_REF_COUNT AND NAME AND // SIZE index.next(); index.next(); index.next(); // getting the actual column we are reading String col = field.asColumn(); // along with actual column we are reading Attachment Ref Count and Name col += "," + field.getAlias() + "." + DBSchema.C_ATTACHMENT_REF_COUNT + ", " + field.getAlias() + "." + DBSchema.C_NAME + ", " + field.getAlias() + "." + DBSchema.C_ATT_SIZE; return col; }
public void index(Record record) { final Long recordId = record.getId(); if (record.isActive()) { final Record anotherRecord = records.putIfAbsent(recordId, record); if (anotherRecord != null) { record = anotherRecord; } else { size.incrementAndGet(); } } else { remove(record); } if (indexValue != null) { Long newValueIndex = -1L; if (record.isActive() && record.hasValueData()) { newValueIndex = (long) record.getValueData().hashCode(); } indexValue.index(newValueIndex, record); } Long[] indexValues = record.getIndexes(); if (indexValues != null && hasIndexedAttributes) { byte[] indexTypes = record.getIndexTypes(); if (indexTypes == null || indexValues.length != indexTypes.length) { throw new IllegalArgumentException( "index and types don't match " + Arrays.toString(indexTypes)); } Collection<Index> indexes = mapIndexes.values(); for (Index index : indexes) { if (indexValues.length > index.getAttributeIndex()) { Long newValue = indexValues[index.getAttributeIndex()]; index.index(newValue, record); } } } }
public void findIndexMatches( Index index, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope, IProgressMonitor progressMonitor) throws IOException { if (progressMonitor != null && progressMonitor.isCanceled()) throw new OperationCanceledException(); resetQuery(); SimpleSet intersectedNames = null; try { index.startQuery(); do { SearchPattern pattern = currentPattern(); EntryResult[] entries = pattern.queryIn(index); if (entries == null) return; SearchPattern decodedResult = pattern.getBlankPattern(); SimpleSet newIntersectedNames = new SimpleSet(3); for (int i = 0, l = entries.length; i < l; i++) { if (progressMonitor != null && progressMonitor.isCanceled()) throw new OperationCanceledException(); EntryResult entry = entries[i]; decodedResult.decodeIndexKey(entry.getWord()); if (pattern.matchesDecodedKey(decodedResult)) { String[] names = entry.getDocumentNames(index); if (intersectedNames != null) { for (int j = 0, n = names.length; j < n; j++) if (intersectedNames.includes(names[j])) newIntersectedNames.add(names[j]); } else { for (int j = 0, n = names.length; j < n; j++) newIntersectedNames.add(names[j]); } } } if (newIntersectedNames.elementSize == 0) return; intersectedNames = newIntersectedNames; } while (hasNextQuery()); } finally { index.stopQuery(); } String containerPath = index.containerPath; char separator = index.separator; Object[] names = intersectedNames.values; for (int i = 0, l = names.length; i < l; i++) if (names[i] != null) acceptMatch( (String) names[i], containerPath, separator, null /*no pattern*/, requestor, participant, scope); // AndPatterns cannot provide the decoded result }
private void clear(Entity ent) { for (Index ei : graph.getIndexList()) { if (ei.getIndex() != IGRAPH) { Entity rem = ei.delete(ent); if (isDebug && rem != null) logger.debug("** EI clear: " + ei.getIndex() + " " + rem); } } }
public Index addIndex(Index index) { Index current = (Index) indexes.get(index.getName()); if (current != null) { throw new MappingException("Index " + index.getName() + " already exists!"); } indexes.put(index.getName(), index); return index; }
@Override public void clear() { for (Index i : index) { storage.removeItem(getId(i.getId())); } index.clear(); updateIndex(); }
public Index[] getIndexesInOrder() { if (mapIndexes.size() == 0) return null; Index[] indexes = new Index[mapIndexes.size()]; for (Index index : mapIndexes.values()) { indexes[index.getAttributeIndex()] = index; } return indexes; }
/** * Closes the specified index. * * @param type index to be closed */ private synchronized void close(final IndexType type) { // close index and invalidate reference final Index index = index(type); if (index != null) { index.close(); set(type, null); } }
Class37(Class353 class353, int i, Index class302, Index class302_6_, Index class302_7_) { aClass302_559 = class302; if (aClass302_559 != null) { int i_8_ = -1 + aClass302_559.method3526(-20871); aClass302_559.method3537(-2, i_8_); } Class345.method3971(class302_7_, 2, true, class302_6_); }
public LinearClassifier createLinearClassifier(double[] weights) { double[][] weights2D; if (objective != null) { weights2D = objective.to2D(weights); } else { weights2D = ArrayUtils.to2D(weights, featureIndex.size(), labelIndex.size()); } return new LinearClassifier<L, F>(weights2D, featureIndex, labelIndex); }
/** * Construct an instance of the class with * * @param structureName * @param index * @throws IOException */ @SuppressWarnings("unchecked") public MapFileLexiconIterator(String structureName, Index index) throws IOException { this( structureName, index.getPath(), index.getPrefix(), (FixedSizeWriteableFactory<Text>) index.getIndexStructure(structureName + "-keyfactory"), (FixedSizeWriteableFactory<LexiconEntry>) index.getIndexStructure(structureName + "-valuefactory")); }
/** * add * * @param i a {@link org.opennms.netmgt.dao.db.Index} object. */ public void add(Index i) { String lowerName = i.getName().toLowerCase(); if (m_nameMap.containsKey(lowerName)) { throw new IllegalArgumentException("Index with name of '" + lowerName + "' already exists."); } m_nameMap.put(lowerName, i); getIndexesForTableCreateIfEmpty(i.getTable().toLowerCase()).add(i); }