19 #if !defined(XALANMAP_HEADER_GUARD_1357924680)
20 #define XALANMAP_HEADER_GUARD_1357924680
43 #pragma warning(disable: 4189)
54 const char *byteArray =
reinterpret_cast<const char*
>(&key);
58 for (
size_type i = 0; i <
sizeof(Key); ++i)
60 result = (result << 1) ^ byteArray[i];
98 template <
class Value>
106 template <
class Value>
114 template <
class XalanMapTraits,
class BaseIterator>
119 typedef typename XalanMapTraits::pointer
pointer;
129 baseIterator(theRhs.baseIterator)
153 return *baseIterator->value;
158 return baseIterator->value;
168 return !(theRhs == *
this);
236 eDefaultMinBuckets = 29u,
237 eDefaultEraseThreshold = 50u,
238 eMinimumBucketSize = 5u
243 MemoryManager& theMemoryManager,
244 double loadFactor = 0.75,
245 size_type minBuckets = eDefaultMinBuckets,
246 size_type eraseThreshold = eDefaultEraseThreshold) :
247 m_memoryManager(&theMemoryManager),
248 m_loadFactor(loadFactor),
249 m_minBuckets(minBuckets),
251 m_entries(theMemoryManager),
252 m_freeEntries(theMemoryManager),
253 m_buckets(theMemoryManager),
255 m_eraseThreshold(eraseThreshold)
261 MemoryManager& theMemoryManager) :
262 m_memoryManager(&theMemoryManager),
263 m_loadFactor(theRhs.m_loadFactor),
264 m_minBuckets(theRhs.m_minBuckets),
266 m_entries(theMemoryManager),
267 m_freeEntries(theMemoryManager),
269 size_type(m_loadFactor * theRhs.size()) + 1,
273 m_eraseThreshold(theRhs.m_eraseThreshold)
277 while(entry != theRhs.
end())
283 assert(m_size == theRhs.
m_size);
289 assert (m_memoryManager != 0);
291 return *m_memoryManager;
298 if (!m_buckets.empty())
302 while(toRemove != m_freeEntries.end())
304 deallocate(toRemove->value);
313 XalanMap theTemp(theRhs, *m_memoryManager);
332 return m_entries.begin();
337 return const_cast<XalanMap*
>(
this)->begin();
342 return m_entries.end();
347 return const_cast<XalanMap*
>(
this)->end();
354 assert(m_buckets.empty() ==
false);
357 assert(index < m_buckets.size());
362 while (pos != bucket.
end())
364 if (!(*pos)->erased && m_equals(key, (*pos)->value->first))
377 return const_cast<XalanMap *
>(
this)->find(key);
386 pos = doCreateEntry(key);
389 return (*pos).second;
395 insert(value.first, value.second);
404 doCreateEntry(key, &data);
438 while (bucketPos != m_buckets.end())
447 assert(m_entries.empty());
456 MemoryManager*
const tempMemoryManager = m_memoryManager;
460 const size_type tempEraseCount = m_eraseCount;
464 const size_type tempEraseTheshold = m_eraseThreshold;
478 if (m_buckets.empty())
487 if (
size_type(m_loadFactor * size()) > m_buckets.size())
494 if (m_freeEntries.empty())
496 m_freeEntries.push_back(
Entry(allocate(1)));
500 Entry& newEntry = m_freeEntries.back();
503 FirstConstructor::construct(
510 SecondConstructor::construct(
511 &newEntry.
value->second,
517 SecondConstructor::construct(
518 &newEntry.
value->second,
522 m_entries.splice(m_entries.end(), m_freeEntries, --m_freeEntries.end());
524 m_buckets[index].push_back(--m_entries.end());
534 #if defined(_MSC_VER) && _MSC_VER <= 1300
535 toRemove.value_type::~value_type();
537 toRemove.~value_type();
539 m_freeEntries.splice(
554 doRemoveEntry(begin());
561 assert(pos != end());
567 if (m_eraseCount == m_eraseThreshold)
580 assert(modulus != 0);
582 return m_hash(key) % modulus;
587 return doHash(key, m_buckets.size());
594 assert(theNewSize != 0);
604 while (entryPos != m_entries.end())
608 entryPos->value->first,
618 m_buckets.swap(temp);
626 assert(m_memoryManager != 0);
628 void* pointer = m_memoryManager->allocate(theBytesNeeded);
630 assert(pointer != 0);
632 return reinterpret_cast<value_type*
>(pointer);
638 assert(m_memoryManager != 0);
640 m_memoryManager->deallocate(pointer);
648 assert(theExtraCapacity > theCurrentSize);
655 return theCurrentSize == 0 ?
664 i != m_buckets.end();
671 while(j != theCurrentBucket.
end())
673 if ((*j)->erased ==
true)
675 j = theCurrentBucket.
erase(j);
687 theCurrentBucket.
size();
690 theCurrentBucket.
capacity() - theCurrentSize;
692 if (theExtraCapacity > theCurrentSize)
695 calculateNewBucketCapacity(
707 theCurrentBucket.
swap(theTempBucket);
745 #if defined(_MSC_VER)
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
size_type operator()(const Key &key) const
Xalan implementation of a hashtable.
MemoryManager & getMemoryManager()
MemoryManager * m_memoryManager
void swap(XalanMap &theRhs)
value_type * allocate(size_type size)
XalanMapIterator< XalanMapIteratorTraits< value_type >, typename EntryListType::iterator > iterator
KeyConstructionTraits::Constructor FirstConstructor
size_type m_eraseThreshold
const_iterator begin() const
XalanMap & operator=(const XalanMap &theRhs)
iterator doCreateEntry(const key_type &key, const data_type *data=0)
size_type doHash(const Key &key) const
iterator find(const key_type &key)
const_iterator find(const key_type &key) const
XalanVector< BucketType, ConstructWithMemoryManagerTraits< BucketType > > BucketTableType
size_type erase(const key_type &key)
BucketTableType::iterator TableIterator
BucketType::iterator BucketIterator
std::pair< const key_type, data_type > value_type
void insert(const value_type &value)
XalanVector< typename EntryListType::iterator > BucketType
void insert(const key_type &key, const data_type &data)
Key key_type
Each map entry is stored in a linked list where an entry consists of a pointer to the key/value pair ...
const_iterator end() const
XalanMap(const XalanMap &theRhs, MemoryManager &theMemoryManager)
ValueConstructionTraits::Constructor SecondConstructor
void deallocate(value_type *pointer)
XalanList< Entry > EntryListType
KeyTraits::Comparator m_equals
XalanMap(MemoryManager &theMemoryManager, double loadFactor=0.75, size_type minBuckets=eDefaultMinBuckets, size_type eraseThreshold=eDefaultEraseThreshold)
XalanMapIterator< XalanMapConstIteratorTraits< value_type >, typename EntryListType::iterator > const_iterator
void doErase(iterator pos)
BucketTableType m_buckets
EntryListType::iterator EntryListIterator
const size_type m_minBuckets
void doRemoveEntry(const iterator &toRemovePos)
EntryListType m_freeEntries
size_type doHash(const Key &key, size_type modulus) const
data_type & operator[](const key_type &key)
static size_type calculateNewBucketCapacity(size_type theCurrentSize, size_type theExtraCapacity)
void swap(ThisType &theOther)
void push_back(const value_type &data)
iterator erase(iterator theFirst, iterator theLast)
size_type capacity() const
void swap(XalanVector< Type > &theLHS, XalanVector< Type > &theRHS)
XalanDOMString & insert(XalanDOMString &theString, XalanDOMString::size_type thePosition, const XalanDOMString &theStringToInsert)
Insert a string into another string.
XalanMapTraits::reference reference
bool operator==(const XalanMapIterator &theRhs) const
XalanMapIterator(const BaseIterator &theRhs)
BaseIterator baseIterator
XalanMapTraits::pointer pointer
reference operator*() const
XalanMapIterator< XalanMapIteratorTraits< value_type >, BaseIterator > Iterator
XalanMapIterator(const Iterator &theRhs)
XalanMapTraits::value_type value_type
std::bidirectional_iterator_tag iterator_category
ptrdiff_t difference_type
pointer operator->() const
bool operator!=(const XalanMapIterator &theRhs) const
XalanMapIterator operator++(int)
XalanMapIterator & operator++()
std::equal_to< Key > Comparator
XalanHasher< Key > Hasher
Entry(value_type *theValue)