put method

void put(
  1. Uint8List key,
  2. int chunk,
  3. int offset,
  4. int length,
)

Inserts or replaces key with a reference to chunk/offset/length.

Implementation

void put(Uint8List key, int chunk, int offset, int length) {
  final hash = VxsCrc32c.compute(key);
  var slot = hash & (_slots.length - 1);
  while (true) {
    final entry = _slots[slot];
    if (entry == 0) {
      final index = _appendEntry(key, hash, chunk, offset, length);
      _slots[slot] = index + 1;
      if (_count * 2 > _slots.length) {
        _rehash();
      }
      return;
    }
    final index = entry - 1;
    if (_hashes[index] == hash &&
        _keyLengths[index] == key.length &&
        _keyEquals(index, key)) {
      _valueChunks[index] = chunk;
      _valueOffsets[index] = offset;
      _valueLengths[index] = length;
      return;
    }
    slot = (slot + 1) & (_slots.length - 1);
  }
}