org.apache.lucene.util.mutable.MutableValueInt Java Examples

The following examples show how to use org.apache.lucene.util.mutable.MutableValueInt. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CopyOnWriteHashMap.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
Leaf<K, V> put(K key, int hash, int hashBits, V value, MutableValueInt newValue) {
    assert hashBits <= 0 : hashBits;
    int slot = -1;
    for (int i = 0; i < keys.length; i++) {
        if (key.equals(keys[i])) {
            slot = i;
            break;
        }
    }

    final K[] keys2;
    final V[] values2;

    if (slot < 0) {
        keys2 = appendElement(keys, key);
        values2 = appendElement(values, value);
        newValue.value = 1;
    } else {
        keys2 = replace(keys, slot, key);
        values2 = replace(values, slot, value);
    }

    return new Leaf<>(keys2, values2);
}
 
Example #2
Source File: CopyOnWriteHashMap.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private InnerNode<K, V> putExisting(K key, int hash, int hashBits, int slot, V value, MutableValueInt newValue) {
    final K[] keys2 = Arrays.copyOf(keys, keys.length);
    final Object[] subNodes2 = Arrays.copyOf(subNodes, subNodes.length);

    final Object previousValue = subNodes2[slot];
    if (previousValue instanceof Node) {
        // insert recursively
        assert keys[slot] == null;
        subNodes2[slot] = ((Node<K, V>) previousValue).put(key, hash, hashBits, value, newValue);
    } else if (keys[slot].equals(key)) {
        // replace the existing entry
        subNodes2[slot] = value;
    } else {
        // hash collision
        final K previousKey = keys[slot];
        final int previousHash = previousKey.hashCode() >>> (TOTAL_HASH_BITS - hashBits);
        Node<K, V> subNode = newSubNode(hashBits);
        subNode = subNode.put(previousKey, previousHash, hashBits, (V) previousValue, newValue);
        subNode = subNode.put(key, hash, hashBits, value, newValue);
        keys2[slot] = null;
        subNodes2[slot] = subNode;
    }
    return new InnerNode<>(mask, keys2, subNodes2);
}
 
Example #3
Source File: IntDocValues.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public ValueFiller getValueFiller() {
  return new ValueFiller() {
    private final MutableValueInt mval = new MutableValueInt();

    @Override
    public MutableValue getValue() {
      return mval;
    }

    @Override
    public void fillValue(int doc) throws IOException {
      mval.value = intVal(doc);
      mval.exists = exists(doc);
    }
  };
}
 
Example #4
Source File: CopyOnWriteHashMap.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
Leaf<K, V> put(K key, int hash, int hashBits, V value, MutableValueInt newValue) {
    assert hashBits <= 0 : hashBits;
    int slot = -1;
    for (int i = 0; i < keys.length; i++) {
        if (key.equals(keys[i])) {
            slot = i;
            break;
        }
    }

    final K[] keys2;
    final V[] values2;

    if (slot < 0) {
        keys2 = appendElement(keys, key);
        values2 = appendElement(values, value);
        newValue.value = 1;
    } else {
        keys2 = replace(keys, slot, key);
        values2 = replace(values, slot, value);
    }

    return new Leaf<>(keys2, values2);
}
 
Example #5
Source File: CopyOnWriteHashMap.java    From crate with Apache License 2.0 6 votes vote down vote up
private InnerNode<K, V> putExisting(K key, int hash, int hashBits, int slot, V value, MutableValueInt newValue) {
    final K[] keys2 = Arrays.copyOf(keys, keys.length);
    final Object[] subNodes2 = Arrays.copyOf(subNodes, subNodes.length);

    final Object previousValue = subNodes2[slot];
    if (previousValue instanceof Node) {
        // insert recursively
        assert keys[slot] == null;
        subNodes2[slot] = ((Node<K, V>) previousValue).put(key, hash, hashBits, value, newValue);
    } else if (keys[slot].equals(key)) {
        // replace the existing entry
        subNodes2[slot] = value;
    } else {
        // hash collision
        final K previousKey = keys[slot];
        final int previousHash = previousKey.hashCode() >>> (TOTAL_HASH_BITS - hashBits);
        Node<K, V> subNode = newSubNode(hashBits);
        subNode = subNode.put(previousKey, previousHash, hashBits, (V) previousValue, newValue);
        subNode = subNode.put(key, hash, hashBits, value, newValue);
        keys2[slot] = null;
        subNodes2[slot] = subNode;
    }
    return new InnerNode<>(mask, keys2, subNodes2);
}
 
Example #6
Source File: CopyOnWriteHashMap.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
InnerNode<K, V> put(K key, int hash, int hashBits, V value, MutableValueInt newValue) {
    final int hash6 = hash & HASH_MASK;
    final int slot = slot(hash6);

    if (exists(hash6)) {
        hash >>>= HASH_BITS;
        hashBits -= HASH_BITS;
        return putExisting(key, hash, hashBits, slot, value, newValue);
    } else {
        newValue.value = 1;
        return putNew(key, hash6, slot, value);
    }
}
 
Example #7
Source File: CopyOnWriteHashMap.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Associate <code>key</code> with <code>value</code> and return a new copy
 * of the hash table. The current hash table is not modified.
 */
public CopyOnWriteHashMap<K, V> copyAndPut(K key, V value) {
    Preconditions.checkArgument(key != null, "null keys are not supported");
    Preconditions.checkArgument(value != null, "null values are not supported");
    final int hash = key.hashCode();
    final MutableValueInt newValue = new MutableValueInt();
    final InnerNode<K, V> newRoot = root.put(key, hash, TOTAL_HASH_BITS, value, newValue);
    final int newSize = size + newValue.value;
    return new CopyOnWriteHashMap<>(newRoot, newSize);
}
 
Example #8
Source File: CopyOnWriteHashMap.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
InnerNode<K, V> put(K key, int hash, int hashBits, V value, MutableValueInt newValue) {
    final int hash6 = hash & HASH_MASK;
    final int slot = slot(hash6);

    if (exists(hash6)) {
        hash >>>= HASH_BITS;
        hashBits -= HASH_BITS;
        return putExisting(key, hash, hashBits, slot, value, newValue);
    } else {
        newValue.value = 1;
        return putNew(key, hash6, slot, value);
    }
}
 
Example #9
Source File: CopyOnWriteHashMap.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Associate <code>key</code> with <code>value</code> and return a new copy
 * of the hash table. The current hash table is not modified.
 */
public CopyOnWriteHashMap<K, V> copyAndPut(K key, V value) {
    if (key == null) {
        throw new IllegalArgumentException("null keys are not supported");
    }
    if (value == null) {
        throw new IllegalArgumentException("null values are not supported");
    }
    final int hash = key.hashCode();
    final MutableValueInt newValue = new MutableValueInt();
    final InnerNode<K, V> newRoot = root.put(key, hash, TOTAL_HASH_BITS, value, newValue);
    final int newSize = size + newValue.value;
    return new CopyOnWriteHashMap<>(newRoot, newSize);
}
 
Example #10
Source File: GroupConverter.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
static Collection<SearchGroup<MutableValue>> toMutable(SchemaField field, Collection<SearchGroup<BytesRef>> values) {
  FieldType fieldType = field.getType();
  List<SearchGroup<MutableValue>> result = new ArrayList<>(values.size());
  for (SearchGroup<BytesRef> original : values) {
    SearchGroup<MutableValue> converted = new SearchGroup<>();
    converted.sortValues = original.sortValues; // ?
    NumberType type = fieldType.getNumberType();
    final MutableValue v;
    switch (type) {
      case INTEGER:
        MutableValueInt mutableInt = new MutableValueInt();
        if (original.groupValue == null) {
          mutableInt.value = 0;
          mutableInt.exists = false;
        } else {
          mutableInt.value = (Integer) fieldType.toObject(field, original.groupValue);
        }
        v = mutableInt;
        break;
      case FLOAT:
        MutableValueFloat mutableFloat = new MutableValueFloat();
        if (original.groupValue == null) {
          mutableFloat.value = 0;
          mutableFloat.exists = false;
        } else {
          mutableFloat.value = (Float) fieldType.toObject(field, original.groupValue);
        }
        v = mutableFloat;
        break;
      case DOUBLE:
        MutableValueDouble mutableDouble = new MutableValueDouble();
        if (original.groupValue == null) {
          mutableDouble.value = 0;
          mutableDouble.exists = false;
        } else {
          mutableDouble.value = (Double) fieldType.toObject(field, original.groupValue);
        }
        v = mutableDouble;
        break;
      case LONG:
        MutableValueLong mutableLong = new MutableValueLong();
        if (original.groupValue == null) {
          mutableLong.value = 0;
          mutableLong.exists = false;
        } else {
          mutableLong.value = (Long) fieldType.toObject(field, original.groupValue);
        }
        v = mutableLong;
        break;
      case DATE:
        MutableValueDate mutableDate = new MutableValueDate();
        if (original.groupValue == null) {
          mutableDate.value = 0;
          mutableDate.exists = false;
        } else {
          mutableDate.value = ((Date)fieldType.toObject(field, original.groupValue)).getTime();
        }
        v = mutableDate;
        break;
      default:
        throw new AssertionError();
    }
    converted.groupValue = v;
    result.add(converted);
  }
  return result;
}
 
Example #11
Source File: PointMerger.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
IntSeg(PointValues points, int capacity) {
  super(points, capacity);
  this.values = new int[capacity];
  this.currentValue = this.mval = new MutableValueInt();
}
 
Example #12
Source File: CopyOnWriteHashMap.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Recursively add a new entry to this node. <code>hashBits</code> is
 * the number of bits that are still set in the hash. When this value
 * reaches a number that is less than or equal to <tt>0</tt>, a leaf
 * node needs to be created since it means that a collision occurred
 * on the 32 bits of the hash.
 */
abstract Node<K, V> put(K key, int hash, int hashBits, V value, MutableValueInt newValue);
 
Example #13
Source File: CopyOnWriteHashMap.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * Recursively add a new entry to this node. <code>hashBits</code> is
 * the number of bits that are still set in the hash. When this value
 * reaches a number that is less than or equal to {@code 0}, a leaf
 * node needs to be created since it means that a collision occurred
 * on the 32 bits of the hash.
 */
abstract Node<K, V> put(K key, int hash, int hashBits, V value, MutableValueInt newValue);