private HollowSetWriteRecord copyToWriteRecord(Set<?> s, FlatRecordWriter flatRecordWriter) { HollowSetWriteRecord rec = (HollowSetWriteRecord)writeRecord(); for(Object o : s) { if(o == null) { throw new NullPointerException(String.format(NULL_ELEMENT_MESSAGE, schema)); } int ordinal = flatRecordWriter == null ? elementMapper.write(o) : elementMapper.writeFlat(o, flatRecordWriter); int hashCode = hashCodeFinder.hashCode(elementMapper.getTypeName(), ordinal, o); rec.addElement(ordinal, hashCode); } return rec; }
private HollowMapWriteRecord copyToWriteRecord(Map<?, ?> m, FlatRecordWriter flatRecordWriter) { HollowMapWriteRecord rec = (HollowMapWriteRecord) writeRecord(); for (Map.Entry<?, ?> entry : m.entrySet()) { Object key = entry.getKey(); if (key == null) { throw new NullPointerException(String.format(NULL_KEY_MESSAGE, schema)); } Object value = entry.getValue(); if (value == null) { throw new NullPointerException(String.format(NULL_VALUE_MESSAGE, schema)); } int keyOrdinal, valueOrdinal; if (flatRecordWriter == null) { keyOrdinal = keyMapper.write(key); valueOrdinal = valueMapper.write(value); } else { keyOrdinal = keyMapper.writeFlat(key, flatRecordWriter); valueOrdinal = valueMapper.writeFlat(value, flatRecordWriter); } int hashCode = hashCodeFinder.hashCode(keyMapper.getTypeName(), keyOrdinal, key); rec.addEntry(keyOrdinal, valueOrdinal, hashCode); } return rec; }
<K, V> int serializeMap(HollowSerializationRecord rec, String keyTypeName, String valueTypeName, Map<K, V> obj) { HollowMapWriteRecord mapRec = (HollowMapWriteRecord)rec.getHollowWriteRecord(); mapRec.reset(); for(Map.Entry<K, V> entry : obj.entrySet()) { if(entry.getKey() != null && entry.getValue() != null) { int keyOrdinal = getFramework().add(keyTypeName, entry.getKey()); int valueOrdinal = getFramework().add(valueTypeName, entry.getValue()); int hashCode = hasher.hashCode(keyTypeName, keyOrdinal, entry.getKey()); mapRec.addEntry(keyOrdinal, valueOrdinal, hashCode); } } return getFramework().getStateEngine().add(rec.getTypeName(), mapRec); }
<T> int serializeSet(HollowSerializationRecord rec, String typeName, Set<T> obj) { HollowSetWriteRecord setRec = (HollowSetWriteRecord)rec.getHollowWriteRecord(); setRec.reset(); for(T t : obj) { if(t != null) { int ordinal = getFramework().add(typeName, t); int hashCode = hasher.hashCode(typeName, ordinal, t); setRec.addElement(ordinal, hashCode); } } return getFramework().getStateEngine().add(rec.getTypeName(), setRec); }
@Override public boolean contains(HollowSet<T> set, int ordinal, Object o) { if(getSchema().getHashKey() != null) { for(int i=0;i<ordinals.length;i++) { if(ordinals[i] != -1 && set.equalsElement(ordinals[i], o)) return true; } } else { int hashCode = dataAccess.getDataAccess().getHashCodeFinder().hashCode(o); int bucket = HashCodes.hashInt(hashCode) & hashMask; while(ordinals[bucket] != -1) { if(set.equalsElement(ordinals[bucket], o)) return true; bucket ++; bucket &= hashMask; } } return false; }
@Override public boolean containsKey(HollowMap<K, V> map, int ordinal, Object key) { if(getSchema().getHashKey() != null) { for(int i=0;i<ordinals.length;i+=2) { if(ordinals[i] != -1 && map.equalsKey(ordinals[i], key)) return true; } } else { int hashCode = dataAccess.getDataAccess().getHashCodeFinder().hashCode(key); int bucket = (HashCodes.hashInt(hashCode) & hashMask) * 2; while(ordinals[bucket] != -1) { if(map.equalsKey(ordinals[bucket], key)) { return true; } bucket += 2; bucket &= ordinals.length - 1; } } return false; }
@Override public boolean containsKey(HollowMap<K, V> map, int ordinal, Object key) { HollowMapEntryOrdinalIterator iter; if(getSchema().getHashKey() != null) { iter = dataAccess.ordinalIterator(ordinal); } else { int hashCode = dataAccess.getDataAccess().getHashCodeFinder().hashCode(key); iter = dataAccess.potentialMatchOrdinalIterator(ordinal, hashCode); } while(iter.next()) { if(map.equalsKey(iter.getKey(), key)) return true; } return false; }
@Override public boolean contains(HollowSet<T> set, int ordinal, Object o) { HollowOrdinalIterator iter; if(getSchema().getHashKey() != null) { iter = dataAccess.ordinalIterator(ordinal); } else { int hashCode = dataAccess.getDataAccess().getHashCodeFinder().hashCode(o); iter = dataAccess.potentialMatchOrdinalIterator(ordinal, hashCode); } int potentialOrdinal = iter.next(); while(potentialOrdinal != HollowOrdinalIterator.NO_MORE_ORDINALS) { if(set.equalsElement(potentialOrdinal, o)) return true; potentialOrdinal = iter.next(); } return false; }
@Override public V get(HollowMap<K, V> map, int ordinal, Object key) { if(getSchema().getHashKey() != null) { for(int i=0;i<ordinals.length;i+=2) { if(ordinals[i] != -1 && map.equalsKey(ordinals[i], key)) return map.instantiateValue(ordinals[i+1]); } } else { int hashCode = dataAccess.getDataAccess().getHashCodeFinder().hashCode(key); int bucket = (HashCodes.hashInt(hashCode) & hashMask) * 2; while(ordinals[bucket] != -1) { if(map.equalsKey(ordinals[bucket], key)) { return map.instantiateValue(ordinals[bucket + 1]); } bucket += 2; bucket &= ordinals.length - 1; } } return null; }
@Override public V get(HollowMap<K, V> map, int ordinal, Object key) { HollowMapEntryOrdinalIterator iter; if(getSchema().getHashKey() != null) { iter = dataAccess.ordinalIterator(ordinal); } else { int hashCode = dataAccess.getDataAccess().getHashCodeFinder().hashCode(key); iter = dataAccess.potentialMatchOrdinalIterator(ordinal, hashCode); } while(iter.next()) { if(map.equalsKey(iter.getKey(), key)) return map.instantiateValue(iter.getValue()); } return null; }