Skip to content
Snippets Groups Projects
Commit 77b552fe authored by Vladimir Davydov's avatar Vladimir Davydov Committed by Vladimir Davydov
Browse files

salad: add LIGHT(count) method

This commit adds a function that retrieves the number of records stored
in a light hash table and makes light users use it instead of accessing
the light count directly. This gives us more freedom of refactoring the
light internals without modifying the code using it.

Needed for #7192

NO_DOC=refactoring
NO_TEST=refactoring
NO_CHANGELOG=refactoring
parent 39deec83
No related branches found
No related tags found
No related merge requests found
...@@ -269,7 +269,7 @@ memtx_hash_index_size(struct index *base) ...@@ -269,7 +269,7 @@ memtx_hash_index_size(struct index *base)
struct memtx_hash_index *index = (struct memtx_hash_index *)base; struct memtx_hash_index *index = (struct memtx_hash_index *)base;
struct space *space = space_by_id(base->def->space_id); struct space *space = space_by_id(base->def->space_id);
/* Substract invisible count. */ /* Substract invisible count. */
return index->hash_table.count - return light_index_count(&index->hash_table) -
memtx_tx_index_invisible_count(in_txn(), space, base); memtx_tx_index_invisible_count(in_txn(), space, base);
} }
...@@ -288,7 +288,7 @@ memtx_hash_index_random(struct index *base, uint32_t rnd, struct tuple **result) ...@@ -288,7 +288,7 @@ memtx_hash_index_random(struct index *base, uint32_t rnd, struct tuple **result)
struct light_index_core *hash_table = &index->hash_table; struct light_index_core *hash_table = &index->hash_table;
*result = NULL; *result = NULL;
if (hash_table->count == 0) if (light_index_count(hash_table) == 0)
return 0; return 0;
rnd %= (hash_table->table_size); rnd %= (hash_table->table_size);
while (!light_index_pos_valid(hash_table, rnd)) { while (!light_index_pos_valid(hash_table, rnd)) {
...@@ -358,7 +358,8 @@ memtx_hash_index_replace(struct index *base, struct tuple *old_tuple, ...@@ -358,7 +358,8 @@ memtx_hash_index_replace(struct index *base, struct tuple *old_tuple,
}); });
if (pos == light_index_end) { if (pos == light_index_end) {
diag_set(OutOfMemory, (ssize_t)hash_table->count, diag_set(OutOfMemory,
(ssize_t)light_index_count(hash_table),
"hash_table", "key"); "hash_table", "key");
return -1; return -1;
} }
......
...@@ -206,6 +206,14 @@ LIGHT(create)(struct LIGHT(core) *ht, size_t extent_size, ...@@ -206,6 +206,14 @@ LIGHT(create)(struct LIGHT(core) *ht, size_t extent_size,
static inline void static inline void
LIGHT(destroy)(struct LIGHT(core) *ht); LIGHT(destroy)(struct LIGHT(core) *ht);
/**
* @brief Number of records stored in hash table
* @param ht - pointer to a hash table struct
* @return number of records
*/
static inline uint32_t
LIGHT(count)(struct LIGHT(core) *ht);
/** /**
* @brief Find a record with given hash and value * @brief Find a record with given hash and value
* @param ht - pointer to a hash table struct * @param ht - pointer to a hash table struct
...@@ -372,6 +380,17 @@ LIGHT(destroy)(struct LIGHT(core) *ht) ...@@ -372,6 +380,17 @@ LIGHT(destroy)(struct LIGHT(core) *ht)
matras_destroy(&ht->mtable); matras_destroy(&ht->mtable);
} }
/**
* @brief Number of records stored in hash table
* @param ht - pointer to a hash table struct
* @return number of records
*/
static inline uint32_t
LIGHT(count)(struct LIGHT(core) *ht)
{
return ht->count;
}
/** /**
* Find a slot (index in the hash table), where an item with * Find a slot (index in the hash table), where an item with
* given hash should be placed. * given hash should be placed.
......
...@@ -96,7 +96,7 @@ simple_test() ...@@ -96,7 +96,7 @@ simple_test()
light_delete(&ht, fnd); light_delete(&ht, fnd);
} }
if (count != ht.count) if (count != light_count(&ht))
fail("count check failed!", "true"); fail("count check failed!", "true");
bool identical = true; bool identical = true;
...@@ -160,7 +160,7 @@ collision_test() ...@@ -160,7 +160,7 @@ collision_test()
light_delete(&ht, fnd); light_delete(&ht, fnd);
} }
if (count != ht.count) if (count != light_count(&ht))
fail("count check failed!", "true"); fail("count check failed!", "true");
bool identical = true; bool identical = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment