new->allocnode = dnode_alloc;
new->freenode = dnode_free;
new->context = NULL;
+ new->cmp_ctx = NULL;
new->nodecount = 0;
new->maxcount = maxcount;
new->nilnode.left = &new->nilnode;
dict->context = context;
}
+void dict_set_cmp_context(dict_t *dict, void *cmp_ctx)
+{
+ dict_assert (!dict->cmp_ctx);
+ dict_assert (dict_count(dict) == 0);
+
+ dict->cmp_ctx = cmp_ctx;
+}
+
#ifdef E2FSCK_NOTUSED
/*
* Free a dynamically allocated dictionary object. Removing the nodes
/* simple binary search adapted for trees that contain duplicate keys */
while (root != nil) {
- result = dict->compare(key, root->key);
+ result = dict->compare(dict->cmp_ctx, key, root->key);
if (result < 0)
root = root->left;
else if (result > 0)
do {
saved = root;
root = root->left;
- while (root != nil && dict->compare(key, root->key))
+ while (root != nil
+ && dict->compare(dict->cmp_ctx, key, root->key))
root = root->right;
} while (root != nil);
return saved;
dnode_t *tentative = 0;
while (root != nil) {
- int result = dict->compare(key, root->key);
+ int result = dict->compare(dict->cmp_ctx, key, root->key);
if (result > 0) {
root = root->right;
dnode_t *tentative = 0;
while (root != nil) {
- int result = dict->compare(key, root->key);
+ int result = dict->compare(dict->cmp_ctx, key, root->key);
if (result < 0) {
root = root->left;
while (where != nil) {
parent = where;
- result = dict->compare(key, where->key);
+ result = dict->compare(dict->cmp_ctx, key, where->key);
/* trap attempts at duplicate key insertion unless it's explicitly allowed */
dict_assert (dict->dupes || result != 0);
if (result < 0)
return tokcount;
}
-static int comparef(const void *key1, const void *key2)
+static int comparef(const void *cmp_ctx, const void *key1, const void *key2)
{
return strcmp(key1, key2);
}
#endif
} dnode_t;
-typedef int (*dict_comp_t)(const void *, const void *);
+typedef int (*dict_comp_t)(const void *, const void *, const void *);
typedef dnode_t *(*dnode_alloc_t)(void *);
typedef void (*dnode_free_t)(dnode_t *, void *);
dnode_alloc_t dict_allocnode;
dnode_free_t dict_freenode;
void *dict_context;
+ void *cmp_ctx;
int dict_dupes;
#else
int dict_dummmy;
extern dict_t *dict_create(dictcount_t, dict_comp_t);
extern void dict_set_allocator(dict_t *, dnode_alloc_t, dnode_free_t, void *);
+extern void dict_set_cmp_context(dict_t *, void *);
extern void dict_destroy(dict_t *);
extern void dict_free_nodes(dict_t *);
extern void dict_free(dict_t *);