raw_hash_set.cc
Go to the documentation of this file.
00001 // Copyright 2018 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
00014 
00015 #include "absl/container/internal/raw_hash_set.h"
00016 
00017 #include <atomic>
00018 #include <cstddef>
00019 
00020 #include "absl/base/config.h"
00021 
00022 namespace absl {
00023 namespace container_internal {
00024 
00025 constexpr size_t Group::kWidth;
00026 
00027 // Returns "random" seed.
00028 inline size_t RandomSeed() {
00029 #if ABSL_HAVE_THREAD_LOCAL
00030   static thread_local size_t counter = 0;
00031   size_t value = ++counter;
00032 #else   // ABSL_HAVE_THREAD_LOCAL
00033   static std::atomic<size_t> counter(0);
00034   size_t value = counter.fetch_add(1, std::memory_order_relaxed);
00035 #endif  // ABSL_HAVE_THREAD_LOCAL
00036   return value ^ static_cast<size_t>(reinterpret_cast<uintptr_t>(&counter));
00037 }
00038 
00039 bool ShouldInsertBackwards(size_t hash, ctrl_t* ctrl) {
00040   // To avoid problems with weak hashes and single bit tests, we use % 13.
00041   // TODO(kfm,sbenza): revisit after we do unconditional mixing
00042   return (H1(hash, ctrl) ^ RandomSeed()) % 13 > 6;
00043 }
00044 
00045 }  // namespace container_internal
00046 }  // namespace absl


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:15