mirror of https://mirror.osredm.com/root/redis.git
HNSW: use node max link property.
This is both more correct in formal terms, and in practical terms as well, as we could over-allocate nodes sometimes.
This commit is contained in:
parent
68d3067125
commit
6e434bcaaf
4
hnsw.c
4
hnsw.c
|
@ -938,8 +938,6 @@ void hnsw_update_worst_neighbor_on_remove(HNSW *index, hnswNode *node, uint32_t
|
||||||
void select_neighbors(HNSW *index, pqueue *candidates, hnswNode *new_node,
|
void select_neighbors(HNSW *index, pqueue *candidates, hnswNode *new_node,
|
||||||
uint32_t layer, uint32_t required_links, int aggressive)
|
uint32_t layer, uint32_t required_links, int aggressive)
|
||||||
{
|
{
|
||||||
uint32_t max_links = (layer == 0) ? index->M*2 : index->M;
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < candidates->count; i++) {
|
for (uint32_t i = 0; i < candidates->count; i++) {
|
||||||
hnswNode *neighbor = pq_get_node(candidates,i);
|
hnswNode *neighbor = pq_get_node(candidates,i);
|
||||||
if (neighbor == new_node) continue; // Don't link node with itself.
|
if (neighbor == new_node) continue; // Don't link node with itself.
|
||||||
|
@ -990,7 +988,7 @@ void select_neighbors(HNSW *index, pqueue *candidates, hnswNode *new_node,
|
||||||
/* If potential neighbor node has space, simply add the new link.
|
/* If potential neighbor node has space, simply add the new link.
|
||||||
* We will have space as well. */
|
* We will have space as well. */
|
||||||
uint32_t n = neighbor->layers[layer].num_links;
|
uint32_t n = neighbor->layers[layer].num_links;
|
||||||
if (n < max_links) {
|
if (n < neighbor->layers[layer].max_links) {
|
||||||
/* Link candidate to new node. */
|
/* Link candidate to new node. */
|
||||||
neighbor->layers[layer].links[n] = new_node;
|
neighbor->layers[layer].links[n] = new_node;
|
||||||
neighbor->layers[layer].num_links++;
|
neighbor->layers[layer].num_links++;
|
||||||
|
|
Loading…
Reference in New Issue