]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common: bitset_set
authorAlex Ainscow <aainscow@uk.ibm.com>
Thu, 27 Mar 2025 11:44:29 +0000 (11:44 +0000)
committerAlex Ainscow <aainscow@uk.ibm.com>
Tue, 22 Apr 2025 07:38:14 +0000 (08:38 +0100)
This bitset_set change relaxes policing of bitset_set, so that
out-of-range can be queried in the contains interface. This means
that callers cam simplifiy calls.  For example:

 if (key == invalid) || !set.contains(key)) {
  do_stuff
 }

 becomes

  if (!set.contains(key)) {
   do_stuff
  }

Signed-off-by: Alex Ainscow <aainscow@uk.ibm.com>
src/common/bitset_set.h

index 12c98de99a4cbbe80bf3d79bb5eeccbc29d0ade7..d6d021449598383669f46c0ae4e476890017c839 100644 (file)
@@ -260,8 +260,9 @@ class bitset_set {
 
   /** @return true if the container contains Key k. */
   bool contains(KeyT k) const {
-    ceph_assert(unsigned_cast(k) < max_bits);
-    ceph_assert(int(k) >= 0);
+    if (unsigned_cast(k) >= max_bits) {
+      return false;
+    }
     return (words[int(k) / bits_per_uint64_t]
       & 1ULL << (int(k) % bits_per_uint64_t));
   }