Example #1
0
static struct radix_tree_node *
alloc_radix_tree_node(struct radix_tree *tree, struct radix_tree_node *parent)
{
	struct radix_tree_node *node;
	size_t size;

	size = sizeof(struct radix_tree_node *) * slot_count(tree);

	node = zalloc(sizeof(struct radix_tree_node) + size);
	if (!node)
		return NULL;

	node->parent = parent;

	return node;
}
Example #2
0
static void
free_radix_tree_node(struct radix_tree *tree, struct radix_tree_node *node,
		     int level)
{
	if (level < level_count(tree) - 1) {
		int i;

		for (i = 0; i < slot_count(tree); i++) {
			if (node->slots[i] == NULL)
				continue;

			free_radix_tree_node(tree, node->slots[i], level + 1);
		}
	}
	free(node);
}
Example #3
0
static void *
radix_tree_last(struct radix_tree *tree, struct radix_tree_node *node,
		int level)
{
	while (level < level_count(tree)) {
		int i;

		for (i = slot_count(tree) - 1; i >= 0; i--)
			if (node->slots[i] != NULL)
				break;

		if (i < 0)
			return NULL;

		node = node->slots[i];
		level++;
	}

	return node;
}
void quotient_filter<Key, Hash, Bits>::regenerate(size_type count) {

  const auto min_slot_count =
      static_cast<size_type>(std::ceil(size() / max_load_factor()));

  const auto new_slot_count = std::max(min_slot_count, count);

  if (!new_slot_count) {
    filter = quotient_filter_fp();
    assert(max_allowed_size() == 0);
    return;
  }

  const size_type q_bits = calc_required_q(new_slot_count);
  const size_type r_bits = hash_bits - q_bits;

  if (q_bits == filter.quotient_bits() && r_bits == filter.remainder_bits()) {
    // Note that remainder_bits() is not always fp - quotient_bits(). If filter
    // was default constructed both of them are zero.
    return; // No regeneration is necessary.
  }

  if (r_bits == 0)
    throw std::length_error("The number of bits of elements (hash values) "
                            "contained in the filter is not enough to hold the "
                            "required slot count.");

  quotient_filter_fp temp(q_bits, r_bits);

  assert(temp.capacity() != filter.capacity() &&
         "Regeneration should not have been required");

  for (const auto hash_value : filter)
    temp.insert(hash_value);

  assert(temp.size() == filter.size()); // Everything is ok.
  filter = std::move(temp);
  assert(count <= slot_count()); // Meets the requirements.
}
 // Returns the current max allowed size according to the number of allocated
 // slots and the maximum load factor.
 size_type max_allowed_size() const noexcept {
   const float ans = max_load_factor() * slot_count();
   return std::min(static_cast<size_type>(ans), slot_count());
 }
 // Hash policy
 float load_factor() const noexcept {
   return empty() ? 0.0f : float(size()) / float(slot_count());
 }