MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / _copy_from

Method _copy_from

libCacheSim/dataStructure/sparsepp/spp.h:2752–2786  ·  view source on GitHub ↗

Used to actually do the rehashing when we grow/shrink a hashtable -----------------------------------------------------------------

Source from the content-addressed store, hash-verified

2750 // Used to actually do the rehashing when we grow/shrink a hashtable
2751 // -----------------------------------------------------------------
2752 void _copy_from(const sparse_hashtable &ht, size_type min_buckets_wanted)
2753 {
2754 clear(); // clear table, set num_deleted to 0
2755
2756 // If we need to change the size of our table, do it now
2757 const size_type resize_to = settings.min_buckets(ht.size(), min_buckets_wanted);
2758
2759 if (resize_to > bucket_count())
2760 {
2761 // we don't have enough buckets
2762 table.resize(resize_to); // sets the number of buckets
2763 settings.reset_thresholds(bucket_count());
2764 }
2765
2766 // We use a normal iterator to get bcks from ht
2767 // We could use insert() here, but since we know there are
2768 // no duplicates, we can be more efficient
2769 assert((bucket_count() & (bucket_count()-1)) == 0); // a power of two
2770 for (const_iterator it = ht.begin(); it != ht.end(); ++it)
2771 {
2772 size_type num_probes = 0; // how many times we've probed
2773 size_type bucknum;
2774 const size_type bucket_count_minus_one = bucket_count() - 1;
2775 for (bucknum = hash(get_key(*it)) & bucket_count_minus_one;
2776 table.test(bucknum); // table.test() OK since no erase()
2777 bucknum = (bucknum + JUMP_(key, num_probes)) & bucket_count_minus_one)
2778 {
2779 ++num_probes;
2780 assert(num_probes < bucket_count()
2781 && "Hashtable is full: an error in key_equal<> or hash<>");
2782 }
2783 table.set(bucknum, *it); // copies the value to here
2784 }
2785 settings.inc_num_ht_copies();
2786 }
2787
2788 // Implementation is like _copy_from, but it destroys the table of the
2789 // "from" guy by freeing sparsetable memory as we iterate. This is

Callers

nothing calls this directly

Calls 11

assertFunction · 0.85
hashClass · 0.85
min_bucketsMethod · 0.80
reset_thresholdsMethod · 0.80
inc_num_ht_copiesMethod · 0.80
sizeMethod · 0.45
resizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
testMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected