You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@apache.org on 2007/02/13 20:42:07 UTC
svn commit: r507180 - /xalan/c/trunk/src/xalanc/Include/XalanMap.hpp
Author: dbertoni
Date: Tue Feb 13 11:42:06 2007
New Revision: 507180
URL: http://svn.apache.org/viewvc?view=rev&rev=507180
Log:
Patch for Jira issue XALANC-613 on HP-UX.
Modified:
xalan/c/trunk/src/xalanc/Include/XalanMap.hpp
Modified: xalan/c/trunk/src/xalanc/Include/XalanMap.hpp
URL: http://svn.apache.org/viewvc/xalan/c/trunk/src/xalanc/Include/XalanMap.hpp?view=diff&rev=507180&r1=507179&r2=507180
==============================================================================
--- xalan/c/trunk/src/xalanc/Include/XalanMap.hpp (original)
+++ xalan/c/trunk/src/xalanc/Include/XalanMap.hpp Tue Feb 13 11:42:06 2007
@@ -49,26 +49,26 @@
class XalanHasher : public XALAN_STD_QUALIFIER unary_function<Key, size_type>
{
public:
- size_type operator()(const Key& key) const
- {
- const char *byteArray = reinterpret_cast<const char*>(&key);
-
- size_type result = 0;
-
- for (size_type i = 0; i < sizeof(Key); ++i)
- {
- result = (result << 1) ^ byteArray[i];
- }
+ size_type operator()(const Key& key) const
+ {
+ const char *byteArray = reinterpret_cast<const char*>(&key);
+
+ size_type result = 0;
+
+ for (size_type i = 0; i < sizeof(Key); ++i)
+ {
+ result = (result << 1) ^ byteArray[i];
+ }
- return result;
- }
+ return result;
+ }
};
template <class Key>
struct XalanMapKeyTraits
{
- typedef XalanHasher<Key> Hasher;
- typedef XALAN_STD_QUALIFIER equal_to<Key> Comparator;
+ typedef XalanHasher<Key> Hasher;
+ typedef XALAN_STD_QUALIFIER equal_to<Key> Comparator;
};
@@ -76,21 +76,21 @@
struct XalanHashMemberPointer
{
- size_type operator() (const Key * key) const
- {
- assert (key != 0);
- return key->hash();
- }
+ size_type operator() (const Key * key) const
+ {
+ assert (key != 0);
+ return key->hash();
+ }
};
template <class Key>
struct XalanHashMemberReference
{
- size_type operator() (const Key& key) const
- {
- return key.hash();
- }
+ size_type operator() (const Key& key) const
+ {
+ return key.hash();
+ }
};
@@ -98,17 +98,17 @@
template <class Value>
struct XalanMapIteratorTraits
{
- typedef Value value_type;
- typedef Value& reference;
- typedef Value* pointer;
+ typedef Value value_type;
+ typedef Value& reference;
+ typedef Value* pointer;
};
template <class Value>
struct XalanMapConstIteratorTraits
{
- typedef Value value_type;
- typedef const Value& reference;
- typedef const Value* pointer;
+ typedef Value value_type;
+ typedef const Value& reference;
+ typedef const Value* pointer;
};
template <class XalanMapTraits, class BaseIterator>
@@ -118,12 +118,12 @@
typedef typename XalanMapTraits::reference reference;
typedef typename XalanMapTraits::pointer pointer;
- typedef ptrdiff_t difference_type;
- typedef XALAN_STD_QUALIFIER bidirectional_iterator_tag iterator_category;
+ typedef ptrdiff_t difference_type;
+ typedef XALAN_STD_QUALIFIER bidirectional_iterator_tag iterator_category;
typedef XalanMapIterator<
- XalanMapIteratorTraits<value_type>,
- BaseIterator> Iterator;
+ XalanMapIteratorTraits<value_type>,
+ BaseIterator> Iterator;
XalanMapIterator(const Iterator & theRhs) :
baseIterator(theRhs.baseIterator)
@@ -137,9 +137,9 @@
XalanMapIterator operator++(int)
{
- XalanMapIterator temp(*this);
- ++baseIterator;
- return temp;
+ XalanMapIterator temp(*this);
+ ++baseIterator;
+ return temp;
}
XalanMapIterator& operator++()
@@ -178,25 +178,27 @@
*
*/
template <
- class Key,
- class Value,
- class KeyTraits = XalanMapKeyTraits<Key> >
+ class Key,
+ class Value,
+ class KeyTraits = XalanMapKeyTraits<Key>,
+ class KeyConstructionTraits = MemoryManagedConstructionTraits<Key>,
+ class ValueConstructionTraits = MemoryManagedConstructionTraits<Value> >
class XalanMap
{
public:
- /**
- * Each map entry is stored in a linked list where an entry
+ /**
+ * Each map entry is stored in a linked list where an entry
* consists of a pointer to the key/value pair and a flag to indicate
* whether the entry has been erased.
* The hash buckets are a vector of pointers into the entry list.
* Deleted entries are spliced into another list and marked 'erased'.
*/
- typedef Key key_type;
- typedef Value data_type;
- typedef size_t size_type;
+ typedef Key key_type;
+ typedef Value data_type;
+ typedef size_t size_type;
- typedef XALAN_STD_QUALIFIER pair<const key_type, data_type> value_type;
+ typedef XALAN_STD_QUALIFIER pair<const key_type, data_type> value_type;
struct Entry
{
@@ -226,8 +228,8 @@
XalanMapConstIteratorTraits<value_type>,
typename EntryListType::iterator> const_iterator;
- typedef typename MemoryManagedConstructionTraits<key_type>::Constructor FirstConstructor;
- typedef typename MemoryManagedConstructionTraits<data_type>::Constructor SecondConstructor;
+ typedef typename KeyConstructionTraits::Constructor FirstConstructor;
+ typedef typename ValueConstructionTraits::Constructor SecondConstructor;
enum
{
@@ -238,48 +240,48 @@
XalanMap(
- MemoryManagerType& theMemoryManager,
- float loadFactor = 0.75,
- size_type minBuckets = eDefaultMinBuckets,
+ MemoryManagerType& theMemoryManager,
+ float loadFactor = 0.75,
+ size_type minBuckets = eDefaultMinBuckets,
size_type eraseThreshold = eDefaultEraseThreshold) :
- m_memoryManager(&theMemoryManager),
- m_loadFactor(loadFactor),
- m_minBuckets(minBuckets),
- m_size(0),
- m_entries(theMemoryManager),
+ m_memoryManager(&theMemoryManager),
+ m_loadFactor(loadFactor),
+ m_minBuckets(minBuckets),
+ m_size(0),
+ m_entries(theMemoryManager),
m_freeEntries(theMemoryManager),
- m_buckets(theMemoryManager),
+ m_buckets(theMemoryManager),
m_eraseCount(0),
m_eraseThreshold(eraseThreshold)
- {
- }
+ {
+ }
- XalanMap(
- const XalanMap& theRhs,
- MemoryManagerType& theMemoryManager) :
+ XalanMap(
+ const XalanMap& theRhs,
+ MemoryManagerType& theMemoryManager) :
m_memoryManager(&theMemoryManager),
- m_loadFactor(theRhs.m_loadFactor),
- m_minBuckets(theRhs.m_minBuckets),
- m_size(0),
- m_entries(theMemoryManager),
+ m_loadFactor(theRhs.m_loadFactor),
+ m_minBuckets(theRhs.m_minBuckets),
+ m_size(0),
+ m_entries(theMemoryManager),
m_freeEntries(theMemoryManager),
- m_buckets(
+ m_buckets(
size_type(m_loadFactor * theRhs.size()) + 1,
BucketType(*m_memoryManager),
theMemoryManager),
m_eraseCount(0),
m_eraseThreshold(theRhs.m_eraseThreshold)
- {
- const_iterator entry = theRhs.begin();
+ {
+ const_iterator entry = theRhs.begin();
while(entry != theRhs.end())
- {
- insert(*entry);
- ++entry;
- }
+ {
+ insert(*entry);
+ ++entry;
+ }
- assert(m_size == theRhs.m_size);
- }
+ assert(m_size == theRhs.m_size);
+ }
MemoryManagerType&
getMemoryManager()
@@ -289,8 +291,8 @@
return *m_memoryManager;
}
- ~XalanMap()
- {
+ ~XalanMap()
+ {
doRemoveEntries();
if (!m_buckets.empty())
@@ -303,121 +305,121 @@
++toRemove;
}
}
- }
+ }
- XalanMap&
+ XalanMap&
operator=(const XalanMap& theRhs)
- {
- XalanMap theTemp(theRhs, *m_memoryManager);
+ {
+ XalanMap theTemp(theRhs, *m_memoryManager);
swap(theTemp);
return *this;
- }
+ }
- size_type size() const
- {
- return m_size;
- }
+ size_type size() const
+ {
+ return m_size;
+ }
- bool empty() const
+ bool empty() const
{
- return m_size == 0;
- }
+ return m_size == 0;
+ }
- iterator begin()
- {
- return m_entries.begin();
- }
+ iterator begin()
+ {
+ return m_entries.begin();
+ }
- const_iterator begin() const
- {
+ const_iterator begin() const
+ {
return const_cast<XalanMap*>(this)->begin();
- }
+ }
- iterator end()
- {
- return m_entries.end();
- }
+ iterator end()
+ {
+ return m_entries.end();
+ }
- const_iterator end() const
- {
+ const_iterator end() const
+ {
return const_cast<XalanMap*>(this)->end();
- }
+ }
- iterator find(const key_type& key)
- {
- if (m_size != 0)
- {
+ iterator find(const key_type& key)
+ {
+ if (m_size != 0)
+ {
assert(m_buckets.empty() == false);
- const size_type index = doHash(key);
+ const size_type index = doHash(key);
assert(index < m_buckets.size());
BucketType& bucket = m_buckets[index];
BucketIterator pos = bucket.begin();
- while (pos != bucket.end())
- {
- if (!(*pos)->erased && m_equals(key, (*pos)->value->first))
- {
- return iterator(*pos);
- }
- ++pos;
- }
- }
-
- return end();
- }
-
- const_iterator find(const key_type& key) const
- {
- return const_cast<XalanMap *>(this)->find(key);
- }
-
- data_type & operator[](const key_type& key)
- {
- iterator pos = find(key);
-
- if (pos == end())
- {
- pos = doCreateEntry(key);
- }
+ while (pos != bucket.end())
+ {
+ if (!(*pos)->erased && m_equals(key, (*pos)->value->first))
+ {
+ return iterator(*pos);
+ }
+ ++pos;
+ }
+ }
+
+ return end();
+ }
+
+ const_iterator find(const key_type& key) const
+ {
+ return const_cast<XalanMap *>(this)->find(key);
+ }
+
+ data_type & operator[](const key_type& key)
+ {
+ iterator pos = find(key);
+
+ if (pos == end())
+ {
+ pos = doCreateEntry(key);
+ }
- return (*pos).second;
- }
+ return (*pos).second;
+ }
- void
+ void
insert(const value_type& value)
- {
- insert(value.first, value.second);
- }
+ {
+ insert(value.first, value.second);
+ }
void insert(const key_type& key, const data_type& data)
- {
- const const_iterator pos = find(key);
+ {
+ const const_iterator pos = find(key);
- if (pos == end())
- {
- doCreateEntry(key, &data);
- }
- }
-
- void erase(iterator pos)
- {
- if (pos != end())
- {
- doErase(pos);
- }
- }
-
- size_type erase(const key_type& key)
- {
- const iterator pos = find(key);
+ if (pos == end())
+ {
+ doCreateEntry(key, &data);
+ }
+ }
+ void erase(iterator pos)
+ {
if (pos != end())
{
- doErase(pos);
+ doErase(pos);
+ }
+ }
+
+ size_type erase(const key_type& key)
+ {
+ const iterator pos = find(key);
+
+ if (pos != end())
+ {
+ doErase(pos);
return 1;
}
@@ -425,19 +427,19 @@
{
return 0;
}
- }
+ }
- void clear()
- {
+ void clear()
+ {
doRemoveEntries();
- TableIterator bucketPos = m_buckets.begin();
+ TableIterator bucketPos = m_buckets.begin();
while (bucketPos != m_buckets.end())
- {
- bucketPos->clear();
- ++bucketPos;
- }
+ {
+ bucketPos->clear();
+ ++bucketPos;
+ }
m_eraseCount = 0;
@@ -445,15 +447,15 @@
assert(m_entries.empty());
}
- void swap(XalanMap& theRhs)
- {
- const size_type tempSize = m_size;
- m_size = theRhs.m_size;
- theRhs.m_size = tempSize;
-
- MemoryManagerType* const tempMemoryManager = m_memoryManager;
- m_memoryManager = theRhs.m_memoryManager;
- theRhs.m_memoryManager = tempMemoryManager;
+ void swap(XalanMap& theRhs)
+ {
+ const size_type tempSize = m_size;
+ m_size = theRhs.m_size;
+ theRhs.m_size = tempSize;
+
+ MemoryManagerType* const tempMemoryManager = m_memoryManager;
+ m_memoryManager = theRhs.m_memoryManager;
+ theRhs.m_memoryManager = tempMemoryManager;
const size_type tempEraseCount = m_eraseCount;
m_eraseCount = theRhs.m_eraseCount;
@@ -463,31 +465,31 @@
m_eraseThreshold = theRhs.m_eraseThreshold;
theRhs.m_eraseThreshold = tempEraseTheshold;
- m_entries.swap(theRhs.m_entries);
+ m_entries.swap(theRhs.m_entries);
m_freeEntries.swap(theRhs.m_freeEntries);
- m_buckets.swap(theRhs.m_buckets);
- }
+ m_buckets.swap(theRhs.m_buckets);
+ }
protected:
iterator doCreateEntry(const key_type & key, const data_type* data = 0)
- {
- // if there are no buckets, create initial minimum set of buckets
- if (m_buckets.empty())
- {
- m_buckets.insert(
+ {
+ // if there are no buckets, create initial minimum set of buckets
+ if (m_buckets.empty())
+ {
+ m_buckets.insert(
m_buckets.begin(),
m_minBuckets,
BucketType(*m_memoryManager));
- }
+ }
- // if the load factor has been reached, rehash
- if (size_type(m_loadFactor * size()) > m_buckets.size())
- {
- rehash();
- }
+ // if the load factor has been reached, rehash
+ if (size_type(m_loadFactor * size()) > m_buckets.size())
+ {
+ rehash();
+ }
- const size_type index = doHash(key);
+ const size_type index = doHash(key);
if (m_freeEntries.empty())
{
@@ -523,11 +525,11 @@
++m_size;
- return iterator(--m_entries.end());
- }
+ return iterator(--m_entries.end());
+ }
- void doRemoveEntry(const iterator & toRemovePos)
- {
+ void doRemoveEntry(const iterator & toRemovePos)
+ {
value_type& toRemove = *toRemovePos;
#if defined(_MSC_VER) && _MSC_VER <= 1300
toRemove.value_type::~value_type();
@@ -541,8 +543,8 @@
toRemovePos.baseIterator->erased = true;
- --m_size;
- }
+ --m_size;
+ }
void
doRemoveEntries()
@@ -553,10 +555,10 @@
}
}
- void
+ void
doErase(iterator pos)
- {
- assert(pos != end());
+ {
+ assert(pos != end());
doRemoveEntry(pos);
@@ -568,37 +570,37 @@
m_eraseCount = 0;
}
- }
+ }
size_type
doHash(
const Key& key,
size_type modulus) const
- {
- return m_hash(key) % modulus;
- }
+ {
+ return m_hash(key) % modulus;
+ }
size_type doHash(const Key & key) const
- {
- return doHash(key, m_buckets.size());
- }
-
- void rehash()
- {
- // grow the number of buckets by 60%
+ {
+ return doHash(key, m_buckets.size());
+ }
+
+ void rehash()
+ {
+ // grow the number of buckets by 60%
const size_type theNewSize = size_type(1.6 * size());
- BucketTableType temp(
+ BucketTableType temp(
theNewSize,
BucketType(*m_memoryManager),
*m_memoryManager);
// rehash each entry assign to bucket and insert into list
- EntryListIterator entryPos = m_entries.begin();
+ EntryListIterator entryPos = m_entries.begin();
while (entryPos != m_entries.end())
- {
- const size_type index =
+ {
+ const size_type index =
doHash(
entryPos->value->first,
theNewSize);
@@ -606,12 +608,12 @@
temp[index].push_back(entryPos);
++entryPos;
- }
+ }
// Now that we've rebuilt the buckets, swap the rebuilt
// buckets with our existing buckets.
m_buckets.swap(temp);
- }
+ }
value_type*
allocate(size_type size)
@@ -704,18 +706,18 @@
}
}
- // Data members...
- typename KeyTraits::Hasher m_hash;
-
- typename KeyTraits::Comparator m_equals;
+ // Data members...
+ typename KeyTraits::Hasher m_hash;
+
+ typename KeyTraits::Comparator m_equals;
MemoryManagerType* m_memoryManager;
- float m_loadFactor;
+ float m_loadFactor;
- const size_type m_minBuckets;
+ const size_type m_minBuckets;
- size_type m_size;
+ size_type m_size;
EntryListType m_entries;
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org