//===--- StringMap.cpp - String Hash table map implementation -------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements the StringMap class. // //===----------------------------------------------------------------------===// #include "llvm/ADT/StringMap.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/ReverseIteration.h" #include "llvm/Support/xxhash.h" usingnamespacellvm; /// Returns the number of buckets to allocate to ensure that the DenseMap can /// accommodate \p NumEntries without need to grow(). static inline unsigned getMinBucketToReserveForEntries(unsigned NumEntries) { … } static inline StringMapEntryBase **createTable(unsigned NewNumBuckets) { … } static inline unsigned *getHashTable(StringMapEntryBase **TheTable, unsigned NumBuckets) { … } uint32_t StringMapImpl::hash(StringRef Key) { … } StringMapImpl::StringMapImpl(unsigned InitSize, unsigned itemSize) { … } void StringMapImpl::init(unsigned InitSize) { … } /// LookupBucketFor - Look up the bucket that the specified string should end /// up in. If it already exists as a key in the map, the Item pointer for the /// specified bucket will be non-null. Otherwise, it will be null. In either /// case, the FullHashValue field of the bucket will be set to the hash value /// of the string. unsigned StringMapImpl::LookupBucketFor(StringRef Name, uint32_t FullHashValue) { … } /// FindKey - Look up the bucket that contains the specified key. If it exists /// in the map, return the bucket number of the key. Otherwise return -1. /// This does not modify the map. int StringMapImpl::FindKey(StringRef Key, uint32_t FullHashValue) const { … } /// RemoveKey - Remove the specified StringMapEntry from the table, but do not /// delete it. This aborts if the value isn't in the table. void StringMapImpl::RemoveKey(StringMapEntryBase *V) { … } /// RemoveKey - Remove the StringMapEntry for the specified key from the /// table, returning it. If the key is not in the table, this returns null. StringMapEntryBase *StringMapImpl::RemoveKey(StringRef Key) { … } /// RehashTable - Grow the table, redistributing values into the buckets with /// the appropriate mod-of-hashtable-size. unsigned StringMapImpl::RehashTable(unsigned BucketNo) { … }