예제 #1
0
void BloomFilter::add(std::string word)
{
  unsigned int tmp = 0;

  tmp = murmur3_32(word.c_str(), word.length(), 0x52ed88ff);
  bitMap[tmp % BITSET_SIZE] = 1;

  for (int i = 0; i < NBHASH - 1; i++)
  {
    tmp = murmur3_32(word.c_str(), word.length(), tmp); 
    bitMap[tmp % BITSET_SIZE] = 1;
  }
}
예제 #2
0
void *seg_ptrtable_get(seg_ptrtable *table, const void *key)
{
  uint32_t hashcode = murmur3_32(key, (uint32_t) table->key_length, table->seed);
  uint32_t bnum = hashcode % table->capacity;

  pt_bucket *buck = &(table->buckets[bnum]);
  int bindex = 0;

  if(buck->content == NULL) {
    /* Bucket empty. */
    return NULL;
  }

  for (int i = 0; i < buck->length; i++) {
    pt_entry *ent = &(buck->content[i]);

    if (
      ent->hashcode == hashcode && ! memcmp(ent->key, key, table->key_length)
    ) {
      /* Found it! */
      return ent->value;
    }
  }

  /* Not present. */
  return NULL;
}
예제 #3
0
bool BloomFilter::isPresent(std::string word)
{
  unsigned int tmp = 0;
  int sum = 0;

  tmp = murmur3_32(word.c_str(), word.length(), 0x52ed88ff);
  sum =  bitMap[tmp % BITSET_SIZE];

  for (int i = 0; i < NBHASH - 1; i++)
  {
    tmp = murmur3_32(word.c_str(), word.length(), tmp); 
    sum += bitMap[tmp % BITSET_SIZE];
   }

  return (sum == 4);
}
예제 #4
0
int hashmap_add(hashmap_t *map, char *key, void *data) {
	hashmap_entry_t *next = malloc(sizeof(hashmap_entry_t));
	if (next == NULL) {
		printf("[ERROR] hashmap_add malloc\n");
		return 0;
	}
	next->key = key;
	next->data = data;
	next->next = NULL;

	uint32_t len = strlen(key);
	uint32_t hash = murmur3_32(key, len, map->hash_seed);
	uint32_t index = hash % map->size;
//	if (strcmp(key, "perpetual") == 0)
//		printf("hashmap_add %s %d %d %d %d\n", key, len, map->hash_seed, hash,
//				murmur3_32_(key, len, map->hash_seed));
	hashmap_entry_t *bucket = map->buckets[index];
	if (bucket) {
		while (bucket->next)
			bucket = bucket->next;
		bucket->next = next;
	} else {
		map->buckets[index] = next;
	}
	map->size_of_buckets[index]++;
	return 1;
}
예제 #5
0
bool BloomFilter::maybe_contains(const void *data, size_t data_size) const {
	size_t n_bits = bits.size() * 8;
	uint32_t seed = _tweak;
	for (uint32_t hash_idx = 0; hash_idx < _hash_count; ++hash_idx) {
		if (!test_bit(bits.data(), murmur3_32(data, data_size, seed) % n_bits)) {
			return false;
		}
		seed += 0xfba4c795;
	}
	return true;
}
예제 #6
0
hashmap_entry_t *hashmap_get(hashmap_t *map, const char *key) {
	if (map == NULL || key == NULL)
		return NULL;

	uint32_t len = strlen(key);
	uint32_t hash = murmur3_32(key, len, map->hash_seed);
	uint32_t index = hash % map->size;
//	printf("hashmap_get %s %d %d %d %d\n", key, len, map->hash_seed, hash,
//			murmur3_32_(key, len, map->hash_seed));
	hashmap_entry_t *bucket = map->buckets[index];
	int bucket_size = map->size_of_buckets[index];
	int i, j = 0;
	for (i = 0; i < bucket_size; i++, bucket = bucket->next) {
		int l = strlen(bucket->key);
		while (j < l && j < len && bucket->key[j] == key[j])
			j++;
		if (j == l && j == len)
			return bucket;
		if (key[j] < bucket->key[j])
			break;
	}
	return NULL;
}
예제 #7
0
seg_err pt_find_or_create_entry(
  seg_ptrtable *table,
  pt_bucket *buckets,
  uint64_t capacity,
  const void *key,
  pt_entry **ent,
  bool *created
) {
  uint32_t hashcode = murmur3_32(key, (uint32_t) table->key_length, table->seed);
  uint32_t bnum = hashcode % capacity;

  pt_bucket *buck = &(buckets[bnum]);
  pt_entry *e = NULL;
  int bindex = 0;

  if (buck->content == NULL) {
    /* Create an empty bucket and return its first slot. */
    buck->capacity = table->settings.init_bucket_capacity;
    buck->length = 0;
    buck->content = calloc(buck->capacity, sizeof(pt_entry));

    if (buck->content == NULL) {
      return SEG_NOMEM("Unable to allocate ptrtable bucket.");
    }

    e = &(buck->content[0]);
  } else {
    /* Search for an item already present with this key. */
    for (int i = 0; i < buck->length; i++) {
      e = &(buck->content[i]);

      if (
        e->hashcode == hashcode && ! memcmp(e->key, key, table->key_length)
      ) {
        /* Found! Return this bucket and mark it as existing. */
        *ent = e;
        *created = false;
        return SEG_OK;
      }
    }

    /* Append and return a new entry at the bucket's end. */
    bindex = buck->length;

    if (buck->length >= buck->capacity) {
      /* Expand an existing bucket that has filled. */
      buck->capacity = buck->capacity * table->settings.bucket_growth_factor;
      buck->content = realloc(buck->content, buck->capacity);

      if (buck->content == NULL) {
        return SEG_NOMEM("Unable to expand ptrtable bucket.");
      }

      memset(buck->content, 0, sizeof(pt_entry) * buck->capacity);
    }

    e = &(buck->content[bindex]);
  }

  /* We either created or extended a bucket. Initialize the new entry. */
  table->count++;
  buck->length++;

  e->hashcode = hashcode;
  e->key = key;

  *ent = e;
  *created = true;

  return SEG_OK;
}
예제 #8
0
size_t Quat::ComputeHash() const {
	return murmur3_32((const char*)this, sizeof(Quat));
}
예제 #9
0
/* Makes a unique key identifying a (font, colour) combination. These are used
 * to bucket characters that can be drawn together. Collisions aren't 
 * catastrophic. */
void update_text_style_key(TextStyle *style)
{
	style->key = 0;
	style->key = murmur3_32(style, sizeof(TextStyle));
}