1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

Rename CStringMap -> StringMap, since it now supports nul characters in the

strings.

llvm-svn: 34064
This commit is contained in:
Chris Lattner 2007-02-08 19:20:57 +00:00
parent 99f0279c54
commit d16cc5ebcb
2 changed files with 25 additions and 25 deletions

View File

@ -1,4 +1,4 @@
//===--- CStringMap.h - CString Hash table map interface --------*- C++ -*-===//
//===--- StringMap.h - String Hash table map interface ----------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -7,12 +7,12 @@
//
//===----------------------------------------------------------------------===//
//
// This file defines the CStringMap class.
// This file defines the StringMap class.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_ADT_CSTRINGMAP_H
#define LLVM_ADT_CSTRINGMAP_H
#ifndef LLVM_ADT_STRINGMAP_H
#define LLVM_ADT_STRINGMAP_H
#include "llvm/Support/Allocator.h"
#include <cstring>
@ -28,17 +28,17 @@ public:
unsigned getKeyLength() const { return StrLen; }
};
/// CStringMapVisitor - Subclasses of this class may be implemented to walk all
/// of the items in a CStringMap.
class CStringMapVisitor {
/// StringMapVisitor - Subclasses of this class may be implemented to walk all
/// of the items in a StringMap.
class StringMapVisitor {
public:
virtual ~CStringMapVisitor();
virtual ~StringMapVisitor();
virtual void Visit(const char *Key, StringMapEntryBase *Value) const = 0;
};
/// CStringMapImpl - This is the base class of CStringMap that is shared among
/// StringMapImpl - This is the base class of StringMap that is shared among
/// all of its instantiations.
class CStringMapImpl {
class StringMapImpl {
protected:
/// ItemBucket - The hash table consists of an array of these. If Item is
/// non-null, this is an extant entry, otherwise, it is a hole.
@ -56,7 +56,7 @@ protected:
unsigned NumItems;
unsigned ItemSize;
protected:
CStringMapImpl(unsigned InitSize, unsigned ItemSize);
StringMapImpl(unsigned InitSize, unsigned ItemSize);
void RehashTable();
/// LookupBucketFor - Look up the bucket that the specified string should end
@ -70,7 +70,7 @@ public:
unsigned getNumBuckets() const { return NumBuckets; }
unsigned getNumItems() const { return NumItems; }
void VisitEntries(const CStringMapVisitor &Visitor) const;
void VisitEntries(const StringMapVisitor &Visitor) const;
};
/// StringMapEntry - This is used to represent one value that is inserted into
@ -97,17 +97,17 @@ public:
};
/// CStringMap - This is an unconventional map that is specialized for handling
/// StringMap - This is an unconventional map that is specialized for handling
/// keys that are "strings", which are basically ranges of bytes. This does some
/// funky memory allocation and hashing things to make it extremely efficient,
/// storing the string data *after* the value in the map.
template<typename ValueTy, typename AllocatorTy = MallocAllocator>
class CStringMap : public CStringMapImpl {
class StringMap : public StringMapImpl {
AllocatorTy Allocator;
typedef StringMapEntry<ValueTy> MapEntryTy;
public:
CStringMap(unsigned InitialSize = 0)
: CStringMapImpl(InitialSize, sizeof(MapEntryTy)) {}
StringMap(unsigned InitialSize = 0)
: StringMapImpl(InitialSize, sizeof(MapEntryTy)) {}
AllocatorTy &getAllocator() { return Allocator; }
const AllocatorTy &getAllocator() const { return Allocator; }
@ -164,7 +164,7 @@ public:
return *NewItem;
}
~CStringMap() {
~StringMap() {
for (ItemBucket *I = TheTable, *E = TheTable+NumBuckets; I != E; ++I) {
if (MapEntryTy *Id = static_cast<MapEntryTy*>(I->Item)) {
// Free memory referenced by the item.

View File

@ -1,4 +1,4 @@
//===--- CStringMap.cpp - CString Hash table map implementation -----------===//
//===--- StringMap.cpp - String Hash table map implementation -------------===//
//
// The LLVM Compiler Infrastructure
//
@ -7,18 +7,18 @@
//
//===----------------------------------------------------------------------===//
//
// This file implements the CStringMap class.
// This file implements the StringMap class.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/CStringMap.h"
#include "llvm/ADT/StringMap.h"
#include <cassert>
using namespace llvm;
CStringMapVisitor::~CStringMapVisitor() {
StringMapVisitor::~StringMapVisitor() {
}
CStringMapImpl::CStringMapImpl(unsigned InitSize, unsigned itemSize) {
StringMapImpl::StringMapImpl(unsigned InitSize, unsigned itemSize) {
assert((InitSize & (InitSize-1)) == 0 &&
"Init Size must be a power of 2 or zero!");
NumBuckets = InitSize ? InitSize : 512;
@ -49,7 +49,7 @@ static unsigned HashString(const char *Start, const char *End) {
/// 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 CStringMapImpl::LookupBucketFor(const char *NameStart,
unsigned StringMapImpl::LookupBucketFor(const char *NameStart,
const char *NameEnd) {
unsigned HTSize = NumBuckets;
unsigned FullHashValue = HashString(NameStart, NameEnd);
@ -92,7 +92,7 @@ unsigned CStringMapImpl::LookupBucketFor(const char *NameStart,
/// RehashTable - Grow the table, redistributing values into the buckets with
/// the appropriate mod-of-hashtable-size.
void CStringMapImpl::RehashTable() {
void StringMapImpl::RehashTable() {
unsigned NewSize = NumBuckets*2;
ItemBucket *NewTableArray = new ItemBucket[NewSize]();
memset(NewTableArray, 0, NewSize*sizeof(ItemBucket));
@ -130,7 +130,7 @@ void CStringMapImpl::RehashTable() {
/// VisitEntries - This method walks through all of the items,
/// invoking Visitor.Visit for each of them.
void CStringMapImpl::VisitEntries(const CStringMapVisitor &Visitor) const {
void StringMapImpl::VisitEntries(const StringMapVisitor &Visitor) const {
for (ItemBucket *IB = TheTable, *E = TheTable+NumBuckets; IB != E; ++IB) {
if (StringMapEntryBase *Id = IB->Item)
Visitor.Visit((char*)Id + ItemSize, Id);