Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
32 Views

unsafe_bucket_size in concurrent_unordered_base is not const?

Hi,

I'm reading the source code of the concurrent_unordered_map, and found it's interface  unsafe_bucket_size is designed with non-const function, 

so just curious is this by design? i guess if some body invoke this method in a const method, the compiler will not allow that.

https://github.com/intel/tbb/blob/tbb_2020/include/tbb/internal/_concurrent_unordered_impl.h

 

// Bucket interface - for debugging
    size_type unsafe_bucket_count() const {
        return my_number_of_buckets;
    }

    size_type unsafe_max_bucket_count() const {
        return segment_size(pointers_per_table-1);
    }

    size_type unsafe_bucket_size(size_type bucket) { // ====> non const?
        size_type item_count = 0;
        if (is_initialized(bucket)) {
            raw_iterator it = get_bucket(bucket);
            ++it;
            for (; it != my_solist.raw_end() && !it.get_node_ptr()->is_dummy(); ++it)
                ++item_count;
        }
        return item_count;
    }

    size_type unsafe_bucket(const key_type& key) const {
        sokey_t order_key = (sokey_t) my_hash_compare(key);
        size_type bucket = order_key % my_number_of_buckets;
        return bucket;
    }

 

0 Kudos
0 Replies