@delali/narsil-react-native 0.3.1-next.153 → 0.3.1-next.155

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,6 +13,7 @@
13
13
  typedef struct {
14
14
  const walk_context *context;
15
15
  int32_t *nearest;
16
+ int32_t *anchored_by;
16
17
  } nearest_pass;
17
18
 
18
19
  typedef struct {
@@ -79,7 +80,10 @@ static int64_t replaceable_slot(const nearest_pass *pass, int32_t host, const in
79
80
  for (uint32_t i = 1; i <= count; i++) {
80
81
  int32_t neighbour = list[i];
81
82
  if (incoming_count(context, neighbour) < 2) { continue; }
82
- if (is_live(context, neighbour) && nearest_in_list(pass, neighbour) == host) { continue; }
83
+ if (is_live(context, neighbour) &&
84
+ (nearest_in_list(pass, neighbour) == host || pass->anchored_by[neighbour] == host)) {
85
+ continue;
86
+ }
83
87
  scored_node scored = {neighbour, pair_distance(context, host, neighbour)};
84
88
  if (farthest == -1 || nearer(farthest_node, scored)) {
85
89
  farthest = i;
@@ -116,15 +120,24 @@ static int link_from(const nearest_pass *pass, back_link link) {
116
120
  linked = 1;
117
121
  }
118
122
  }
123
+ if (linked) { pass->anchored_by[ordinal] = host; }
119
124
  node_unlock(context, host);
120
125
  return linked;
121
126
  }
122
127
 
123
128
  narsil_status link_from_nearest(const walk_context *context) {
124
129
  size_t slots = context->slots;
125
- nearest_pass pass = {context, malloc((slots == 0 ? 1 : slots) * sizeof(int32_t))};
126
- if (pass.nearest == NULL) { return NARSIL_OUT_OF_MEMORY; }
127
- for (size_t i = 0; i < slots; i++) { pass.nearest[i] = NEAREST_NOT_YET_FOUND; }
130
+ size_t allocated = (slots == 0 ? 1 : slots) * sizeof(int32_t);
131
+ nearest_pass pass = {context, malloc(allocated), malloc(allocated)};
132
+ if (pass.nearest == NULL || pass.anchored_by == NULL) {
133
+ free(pass.nearest);
134
+ free(pass.anchored_by);
135
+ return NARSIL_OUT_OF_MEMORY;
136
+ }
137
+ for (size_t i = 0; i < slots; i++) {
138
+ pass.nearest[i] = NEAREST_NOT_YET_FOUND;
139
+ pass.anchored_by[i] = NO_NODE;
140
+ }
128
141
  int32_t hosts[NEAREST_LINK_FALLBACK_HOSTS];
129
142
  for (uint32_t ordinal = 0; ordinal < slots; ordinal++) {
130
143
  _Atomic(uint8_t) *due = atomic_byte(context->graph->nearest_link_due, ordinal);
@@ -143,5 +156,6 @@ narsil_status link_from_nearest(const walk_context *context) {
143
156
  }
144
157
  }
145
158
  free(pass.nearest);
159
+ free(pass.anchored_by);
146
160
  return NARSIL_OK;
147
161
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delali/narsil-react-native",
3
- "version": "0.3.1-next.153",
3
+ "version": "0.3.1-next.155",
4
4
  "description": "Narsil for React Native: keyword and vector search on the phone, with the index kept in durable files.",
5
5
  "author": "Delali (https://sondelali.com)",
6
6
  "license": "Apache-2.0",
@@ -53,7 +53,7 @@
53
53
  ],
54
54
  "sideEffects": false,
55
55
  "peerDependencies": {
56
- "@delali/narsil": "0.3.1-next.153",
56
+ "@delali/narsil": "0.3.1-next.155",
57
57
  "expo": "*",
58
58
  "react-native": "*",
59
59
  "react-native-nitro-modules": "*",
@@ -75,7 +75,7 @@
75
75
  "react-native-nitro-modules": "0.37.1",
76
76
  "react-native-worklets": "0.13.0",
77
77
  "typescript": "5.9.3",
78
- "@delali/narsil": "0.3.1-next.153"
78
+ "@delali/narsil": "0.3.1-next.155"
79
79
  },
80
80
  "dependencies": {
81
81
  "web-streams-polyfill": "4.3.0"