aboutsummaryrefslogtreecommitdiff
path: root/collections/map/map.c
diff options
context:
space:
mode:
Diffstat (limited to 'collections/map/map.c')
-rw-r--r--collections/map/map.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/collections/map/map.c b/collections/map/map.c
index 5ad0b65..b0e095e 100644
--- a/collections/map/map.c
+++ b/collections/map/map.c
@@ -497,6 +497,55 @@ void *key;
return ret;
}
+void map_swap(root, ikey, jkey)
+map *root;
+void *ikey, *jkey;
+{
+ struct map_node *tmp, *inode, *jnode;
+ void *tmp_val;
+ int cmp;
+
+ tmp = root->root;
+
+searchi:
+ if (!tmp)
+ return;
+
+ cmp = root->cmp(ikey, tmp->key);
+ if (cmp < 0) {
+ tmp = tmp->left;
+ goto searchi;
+ }
+ if (cmp > 0) {
+ tmp = tmp->right;
+ goto searchi;
+ }
+
+ inode = tmp;
+
+ tmp = root->root;
+searchj:
+ if (!tmp)
+ return;
+
+ cmp = root->cmp(jkey, tmp->key);
+ if (cmp < 0) {
+ tmp = tmp->left;
+ goto searchj;
+ }
+ if (cmp > 0) {
+ tmp = tmp->right;
+ goto searchj;
+ }
+
+ jnode = tmp;
+ tmp_val = jnode->val;
+ jnode->val = inode->val;
+ inode->val = tmp_val;
+
+ return;
+}
+
void map_clear_aux(root)
struct map_node *root;
{