Browse code

Add missing function.

Török Edvin authored on 2010/03/25 00:59:41
Showing 3 changed files
... ...
@@ -504,8 +504,7 @@ int32_t cli_bcapi_hashset_remove(struct cli_bc_ctx *ctx , int32_t id, uint32_t k
504 504
     struct cli_hashset *s = get_hashset(ctx, id);
505 505
     if (!s)
506 506
 	return -1;
507
-//    return cli_hashset_removekey(s, key);
508
-    return -1;
507
+    return cli_hashset_removekey(s, key);
509 508
 }
510 509
 
511 510
 int32_t cli_bcapi_hashset_contains(struct cli_bc_ctx *ctx , int32_t id, uint32_t key)
... ...
@@ -453,6 +453,7 @@ void cli_hashset_destroy(struct cli_hashset* hs)
453 453
 
454 454
 #define BITMAP_CONTAINS(bmap, val) ((bmap)[(val) >> 5] & (1 << ((val) & 0x1f)))
455 455
 #define BITMAP_INSERT(bmap, val) ((bmap)[(val) >> 5] |= (1 << ((val) & 0x1f)))
456
+#define BITMAP_REMOVE(bmap, val) ((bmap)[(val) >> 5] &= ~(1 << ((val) & 0x1f)))
456 457
 
457 458
 /*
458 459
  * searches the hashset for the @key.
... ...
@@ -475,7 +476,6 @@ static inline size_t cli_hashset_search(const struct cli_hashset* hs, const uint
475 475
 	return idx;
476 476
 }
477 477
 
478
-
479 478
 static void cli_hashset_addkey_internal(struct cli_hashset* hs, const uint32_t key)
480 479
 {
481 480
 	const size_t idx = cli_hashset_search(hs, key);
... ...
@@ -529,6 +529,16 @@ int cli_hashset_addkey(struct cli_hashset* hs, const uint32_t key)
529 529
 	return 0;
530 530
 }
531 531
 
532
+int cli_hashset_removekey(struct cli_hashset* hs, const uint32_t key)
533
+{
534
+    const size_t idx = cli_hashset_search(hs, key);
535
+    if (BITMAP_CONTAINS(hs->bitmap, idx)) {
536
+	BITMAP_REMOVE(hs->bitmap, idx);
537
+	hs->keys[idx] = 0;
538
+	hs->count--;
539
+    }
540
+}
541
+
532 542
 int cli_hashset_contains(const struct cli_hashset* hs, const uint32_t key)
533 543
 {
534 544
 	const size_t idx =  cli_hashset_search(hs, key);
... ...
@@ -104,6 +104,7 @@ int cli_hashset_contains(const struct cli_hashset* hs, const uint32_t key);
104 104
 int cli_hashset_clear(struct cli_hashset* hs);
105 105
 void cli_hashset_destroy(struct cli_hashset* hs);
106 106
 ssize_t cli_hashset_toarray(const struct cli_hashset* hs, uint32_t** array);
107
+int cli_hashset_removekey(struct cli_hashset* hs, const uint32_t key);
107 108
 
108 109
 /* Initializes the set without allocating memory, you can do lookups on it
109 110
  * using _contains_maybe_noalloc. You need to initialize it using _init