uint8_t nr_child;
uint8_t *values;
struct cds_ja_inode_flag **pointers;
- struct cds_ja_inode_flag *ptr = NULL;
+ struct cds_ja_inode_flag *ptr, *match_ptr = NULL;
unsigned int i;
- int match_idx = -1, match_v;
+ int match_v;
assert(type->type_class == RCU_JA_LINEAR || type->type_class == RCU_JA_POOL);
assert(dir == JA_LEFT || dir == JA_RIGHT);
if (dir == JA_LEFT) {
if ((int) v < n && (int) v > match_v) {
match_v = v;
- match_idx = i;
+ match_ptr = ptr;
}
} else {
if ((int) v > n && (int) v < match_v) {
match_v = v;
- match_idx = i;
+ match_ptr = ptr;
}
}
}
- if (match_idx < 0) {
+ if (!match_ptr) {
return NULL;
}
assert(match_v >= 0 && match_v < JA_ENTRY_PER_NODE);
*result_key = (uint8_t) match_v;
- ptr = rcu_dereference(pointers[match_idx]);
- return ptr;
+ return match_ptr;
}
static
unsigned int tree_depth, i;
struct cds_ja_inode_flag *node_flag;
- if (caa_unlikely(key > ja->key_max))
+ if (caa_unlikely(key > ja->key_max || key == UINT64_MAX))
return NULL;
tree_depth = ja->tree_depth;
node_flag = rcu_dereference(ja->root);
switch (mode) {
case JA_LOOKUP_BE:
- if (caa_unlikely(key > ja->key_max))
- return NULL;
- break;
case JA_LOOKUP_AE:
- if (caa_unlikely(key > ja->key_max))
+ if (caa_unlikely(key > ja->key_max || key == UINT64_MAX))
return NULL;
break;
default:
**node_flag_ptr;
int ret;
- if (caa_unlikely(key > ja->key_max)) {
+ if (caa_unlikely(key > ja->key_max || key == UINT64_MAX)) {
return -EINVAL;
}
tree_depth = ja->tree_depth;
int nr_snapshot;
int ret;
- if (caa_unlikely(key > ja->key_max))
+ if (caa_unlikely(key > ja->key_max || key == UINT64_MAX))
return -EINVAL;
tree_depth = ja->tree_depth;
{
}
+/*
+ * Note: key UINT64_MAX is reserved internally for iteration.
+ */
+
/*
* cds_ja_lookup - look up by key.
* @ja: the Judy array.
*/
#define cds_ja_for_each_key_rcu(ja, key, pos) \
for ((key) = 0; \
- ((pos) = cds_ja_lookup_above_equal(ja, key, &(key))); )
+ ((key) != UINT64_MAX ? \
+ ((pos) = cds_ja_lookup_above_equal(ja, key, &(key))) : 0); \
+ (key)++)
/*
* cds_ja_for_each_key_prev_rcu: Iterate over all keys in descending order.
* Safe against node removal during iteration.
*/
#define cds_ja_for_each_key_prev_rcu(ja, key, pos) \
- for ((key) = UINT64_MAX; \
- ((pos) = cds_ja_lookup_below_equal(ja, key, &(key))); )
+ for ((key) = UINT64_MAX - 1; \
+ ((key) != UINT64_MAX ? \
+ ((pos) = cds_ja_lookup_below_equal(ja, key, &(key))) : 0); \
+ (key)--)
#ifdef __cplusplus
}