static sparkey_returncode hash_copy()

in src/hashwriter.c [298:313]


static sparkey_returncode hash_copy(uint8_t *hashtable, uint8_t *buf, size_t buffer_size, sparkey_hashheader *old_header, sparkey_hashheader *new_header) {
  int slot_size = old_header->address_size + old_header->hash_size;
  for (unsigned int i = 0; i < buffer_size; i += slot_size) {
    uint64_t hash = old_header->hash_algorithm.read_hash(buf, i);
    uint64_t position = read_addr(buf, i + old_header->hash_size, old_header->address_size);

    int entry_index = (int) (position) & old_header->entry_block_bitmask;
    position >>= old_header->entry_block_bits;

    uint64_t wanted_slot = hash % new_header->hash_capacity;
    if (position != 0) {
      RETHROW(hash_put(wanted_slot, hash, hashtable, new_header, NULL, NULL, NULL, (position << new_header->entry_block_bits) | entry_index));
    }
  }
  return SPARKEY_SUCCESS;
}