From f173112f88dcf6e63bf36810c6b734ef7991b3a8 Mon Sep 17 00:00:00 2001 From: Alan Wright Date: Mon, 7 May 2012 21:42:28 +0200 Subject: [PATCH] Now able to use the default std::allocator instead of the custom Allocator. --- bin/.gitignore | 1 - include/BitSet.h | 10 +- include/Collection.h | 96 +++++++++--------- include/Config.h | 3 + include/HashMap.h | 58 +++++------ include/HashSet.h | 42 ++++---- include/Lucene.h | 46 ++++----- include/{Allocator.h => LuceneAllocator.h} | 98 ++++++++++--------- include/LuceneFactory.h | 20 ++-- include/Map.h | 48 ++++----- include/PriorityQueue.h | 60 ++++++------ include/Set.h | 50 +++++----- include/SimpleLRUCache.h | 22 ++--- src/core/msvc/lucene++.vcproj | 4 +- .../{Allocator.cpp => LuceneAllocator.cpp} | 10 +- 15 files changed, 289 insertions(+), 279 deletions(-) delete mode 100644 bin/.gitignore rename include/{Allocator.h => LuceneAllocator.h} (62%) rename src/core/util/{Allocator.cpp => LuceneAllocator.cpp} (97%) diff --git a/bin/.gitignore b/bin/.gitignore deleted file mode 100644 index f59ec20a..00000000 --- a/bin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* \ No newline at end of file diff --git a/include/BitSet.h b/include/BitSet.h index 2598f8f9..3fa9cdd3 100644 --- a/include/BitSet.h +++ b/include/BitSet.h @@ -17,13 +17,13 @@ namespace Lucene public: BitSet(uint32_t size = 0); virtual ~BitSet(); - + LUCENE_CLASS(BitSet); - + protected: - typedef boost::dynamic_bitset< uint64_t, Allocator > bitset_type; + typedef boost::dynamic_bitset< uint64_t, LuceneAllocator > bitset_type; bitset_type bitSet; - + public: const uint64_t* getBits(); void clear(); @@ -56,7 +56,7 @@ namespace Lucene bool intersectsBitSet(BitSetPtr set) const; uint32_t cardinality(); void resize(uint32_t size); - + virtual bool equals(LuceneObjectPtr other); virtual int32_t hashCode(); virtual LuceneObjectPtr clone(LuceneObjectPtr other = LuceneObjectPtr()); diff --git a/include/Collection.h b/include/Collection.h index d785ecdc..2e05a822 100644 --- a/include/Collection.h +++ b/include/Collection.h @@ -19,18 +19,18 @@ namespace Lucene public: typedef Collection this_type; typedef boost::shared_ptr shared_ptr; - typedef std::vector< TYPE, Allocator > collection_type; + typedef std::vector< TYPE, LuceneAllocator > collection_type; typedef typename collection_type::iterator iterator; typedef typename collection_type::const_iterator const_iterator; typedef TYPE value_type; - + virtual ~Collection() { } - + protected: boost::shared_ptr container; - + public: static this_type newInstance(int32_t size = 0) { @@ -38,7 +38,7 @@ namespace Lucene instance.container = Lucene::newInstance(size); return instance; } - + template static this_type newInstance(ITER first, ITER last) { @@ -46,12 +46,12 @@ namespace Lucene instance.container = Lucene::newInstance(first, last); return instance; } - + void reset() { resize(0); } - + void resize(int32_t size) { if (size == 0) @@ -59,128 +59,128 @@ namespace Lucene else container->resize(size); } - + int32_t size() const { return (int32_t)container->size(); } - + bool empty() const { return container->empty(); } - + void clear() { container->clear(); } - + iterator begin() { return container->begin(); } - + iterator end() { return container->end(); } - + const_iterator begin() const { return container->begin(); } - + const_iterator end() const { return container->end(); } - + void add(const TYPE& type) { container->push_back(type); } - + void add(int32_t pos, const TYPE& type) { container->insert(container->begin() + pos, type); } - + template void addAll(ITER first, ITER last) { container->insert(container->end(), first, last); } - + template void insert(ITER pos, const TYPE& type) { container->insert(pos, type); } - + template ITER remove(ITER pos) { return container->erase(pos); } - + template ITER remove(ITER first, ITER last) { return container->erase(first, last); } - + void remove(const TYPE& type) { container->erase(std::remove(container->begin(), container->end(), type), container->end()); } - + template void remove_if(PRED comp) { container->erase(std::remove_if(container->begin(), container->end(), comp), container->end()); } - + TYPE removeFirst() { TYPE front = container->front(); container->erase(container->begin()); return front; } - + TYPE removeLast() { TYPE back = container->back(); container->pop_back(); return back; } - + iterator find(const TYPE& type) { return std::find(container->begin(), container->end(), type); } - + template iterator find_if(PRED comp) { return std::find_if(container->begin(), container->end(), comp); } - + bool contains(const TYPE& type) const { return (std::find(container->begin(), container->end(), type) != container->end()); } - + template bool contains_if(PRED comp) const { return (std::find_if(container->begin(), container->end(), comp) != container->end()); } - + bool equals(const this_type& other) const { return equals(other, std::equal_to()); } - + template bool equals(const this_type& other, PRED comp) const { @@ -188,48 +188,48 @@ namespace Lucene return false; return std::equal(container->begin(), container->end(), other.container->begin(), comp); } - + int32_t hashCode() { return (int32_t)(int64_t)container.get(); } - + void swap(this_type& other) { container.swap(other->container); } - + TYPE& operator[] (int32_t pos) { return (*container)[pos]; } - + const TYPE& operator[] (int32_t pos) const { return (*container)[pos]; } - + operator bool() const { return container; } - + bool operator! () const { return !container; } - + bool operator== (const this_type& other) { return (container == other.container); } - + bool operator!= (const this_type& other) { return (container != other.container); } }; - + template Collection newCollection(const TYPE& a1) { @@ -237,7 +237,7 @@ namespace Lucene result.add(a1); return result; } - + template Collection newCollection(const TYPE& a1, const TYPE& a2) { @@ -245,7 +245,7 @@ namespace Lucene result.add(a2); return result; } - + template Collection newCollection(const TYPE& a1, const TYPE& a2, const TYPE& a3) { @@ -253,7 +253,7 @@ namespace Lucene result.add(a3); return result; } - + template Collection newCollection(const TYPE& a1, const TYPE& a2, const TYPE& a3, const TYPE& a4) { @@ -261,7 +261,7 @@ namespace Lucene result.add(a4); return result; } - + template Collection newCollection(const TYPE& a1, const TYPE& a2, const TYPE& a3, const TYPE& a4, const TYPE& a5) { @@ -269,7 +269,7 @@ namespace Lucene result.add(a5); return result; } - + template Collection newCollection(const TYPE& a1, const TYPE& a2, const TYPE& a3, const TYPE& a4, const TYPE& a5, const TYPE& a6) { @@ -277,7 +277,7 @@ namespace Lucene result.add(a6); return result; } - + template Collection newCollection(const TYPE& a1, const TYPE& a2, const TYPE& a3, const TYPE& a4, const TYPE& a5, const TYPE& a6, const TYPE& a7) { @@ -285,7 +285,7 @@ namespace Lucene result.add(a7); return result; } - + template Collection newCollection(const TYPE& a1, const TYPE& a2, const TYPE& a3, const TYPE& a4, const TYPE& a5, const TYPE& a6, const TYPE& a7, const TYPE& a8) { @@ -293,7 +293,7 @@ namespace Lucene result.add(a8); return result; } - + template Collection newCollection(const TYPE& a1, const TYPE& a2, const TYPE& a3, const TYPE& a4, const TYPE& a5, const TYPE& a6, const TYPE& a7, const TYPE& a8, const TYPE& a9) { @@ -301,7 +301,7 @@ namespace Lucene result.add(a9); return result; } - + template Collection newCollection(const TYPE& a1, const TYPE& a2, const TYPE& a3, const TYPE& a4, const TYPE& a5, const TYPE& a6, const TYPE& a7, const TYPE& a8, const TYPE& a9, const TYPE& a10) { diff --git a/include/Config.h b/include/Config.h index 90c55790..89725fcd 100644 --- a/include/Config.h +++ b/include/Config.h @@ -77,6 +77,9 @@ // Define to enable cyclic checking in debug builds // #define LPP_USE_CYCLIC_CHECK +// Define to use custom allocator (useful in Windows builds and when using nedmalloc) +#define LPP_USE_ALLOCATOR + // Define to use nedmalloc memory allocator // #define LPP_USE_NEDMALLOC diff --git a/include/HashMap.h b/include/HashMap.h index a01fb551..2d40f5dd 100644 --- a/include/HashMap.h +++ b/include/HashMap.h @@ -19,19 +19,19 @@ namespace Lucene public: typedef HashMap this_type; typedef std::pair key_value; - typedef boost::unordered_map< KEY, VALUE, HASH, EQUAL, Allocator > map_type; + typedef boost::unordered_map< KEY, VALUE, HASH, EQUAL, LuceneAllocator > map_type; typedef typename map_type::iterator iterator; typedef typename map_type::const_iterator const_iterator; typedef KEY key_type; typedef VALUE value_type; - + virtual ~HashMap() { } - + protected: boost::shared_ptr mapContainer; - + public: static this_type newInstance() { @@ -39,114 +39,114 @@ namespace Lucene instance.mapContainer = Lucene::newInstance(); return instance; } - + void reset() { mapContainer.reset(); } - + int32_t size() const { return (int32_t)mapContainer->size(); } - + bool empty() const { return mapContainer->empty(); } - + void clear() { mapContainer->clear(); } - + iterator begin() { return mapContainer->begin(); } - + iterator end() { return mapContainer->end(); } - + const_iterator begin() const { return mapContainer->begin(); } - + const_iterator end() const { return mapContainer->end(); } - + operator bool() const { return mapContainer; } - + bool operator! () const { return !mapContainer; } - + map_type& operator= (const map_type& other) { mapContainer = other.mapContainer; return *this; } - + void put(const KEY& key, const VALUE& value) { (*mapContainer)[key] = value; } - + template void putAll(ITER first, ITER last) { for (iterator current = first; current != last; ++current) (*mapContainer)[current->first] = current->second; } - + template void remove(ITER pos) { mapContainer->erase(pos); } - + template ITER remove(ITER first, ITER last) { return mapContainer->erase(first, last); } - + bool remove(const KEY& key) { return (mapContainer->erase(key) > 0); } - + iterator find(const KEY& key) { return mapContainer->find(key); } - + VALUE get(const KEY& key) const { iterator findValue = mapContainer->find(key); return findValue == mapContainer->end() ? VALUE() : findValue->second; } - + bool contains(const KEY& key) const { return (mapContainer->find(key) != mapContainer->end()); } - + VALUE& operator[] (const KEY& key) { return (*mapContainer)[key]; } }; - + /// Utility template class to handle weak keyed maps template < class KEY, class VALUE, class HASH = boost::hash, class EQUAL = std::equal_to > class WeakHashMap : public HashMap @@ -154,16 +154,16 @@ namespace Lucene public: typedef WeakHashMap this_type; typedef std::pair key_value; - typedef typename boost::unordered_map< KEY, VALUE, HASH, EQUAL, Allocator > map_type; + typedef typename boost::unordered_map< KEY, VALUE, HASH, EQUAL, LuceneAllocator > map_type; typedef typename map_type::iterator iterator; - + static this_type newInstance() { this_type instance; instance.mapContainer = Lucene::newInstance(); return instance; } - + void removeWeak() { if (!this->mapContainer || this->mapContainer->empty()) @@ -176,7 +176,7 @@ namespace Lucene } this->mapContainer->swap(clearCopy); } - + VALUE get(const KEY& key) { iterator findValue = this->mapContainer->find(key); diff --git a/include/HashSet.h b/include/HashSet.h index d65979a8..cefd5337 100644 --- a/include/HashSet.h +++ b/include/HashSet.h @@ -18,18 +18,18 @@ namespace Lucene { public: typedef HashSet this_type; - typedef boost::unordered_set< TYPE, HASH, EQUAL, Allocator > set_type; + typedef boost::unordered_set< TYPE, HASH, EQUAL, LuceneAllocator > set_type; typedef typename set_type::iterator iterator; typedef typename set_type::const_iterator const_iterator; typedef TYPE value_type; - + virtual ~HashSet() { } - + protected: boost::shared_ptr setContainer; - + public: static this_type newInstance() { @@ -37,7 +37,7 @@ namespace Lucene instance.setContainer = Lucene::newInstance(); return instance; } - + template static this_type newInstance(ITER first, ITER last) { @@ -45,84 +45,84 @@ namespace Lucene instance.setContainer = Lucene::newInstance(first, last); return instance; } - + void reset() { setContainer.reset(); } - + int32_t size() const { return (int32_t)setContainer->size(); } - + bool empty() const { return setContainer->empty(); } - + void clear() { setContainer->clear(); } - + iterator begin() { return setContainer->begin(); } - + iterator end() { return setContainer->end(); } - + const_iterator begin() const { return setContainer->begin(); } - + const_iterator end() const { return setContainer->end(); } - + operator bool() const { return setContainer; } - + bool operator! () const { return !setContainer; } - + set_type& operator= (const set_type& other) { setContainer = other.setContainer; return *this; } - + bool add(const TYPE& type) { return setContainer->insert(type).second; } - + template void addAll(ITER first, ITER last) { setContainer->insert(first, last); } - + bool remove(const TYPE& type) { return (setContainer->erase(type) > 0); } - + iterator find(const TYPE& type) { return setContainer->find(type); } - + bool contains(const TYPE& type) const { return (setContainer->find(type) != setContainer->end()); diff --git a/include/Lucene.h b/include/Lucene.h index 5303cd46..838785fa 100644 --- a/include/Lucene.h +++ b/include/Lucene.h @@ -35,7 +35,7 @@ using boost::uint64_t; #define SIZEOF_ARRAY(arr) (sizeof(arr) / sizeof((arr)[0])) #include "LuceneTypes.h" -#include "Allocator.h" +#include "LuceneAllocator.h" namespace boost { @@ -55,16 +55,16 @@ namespace boost namespace Lucene { - typedef std::basic_string< char, std::char_traits, Allocator > SingleString; - typedef std::basic_ostringstream< char, std::char_traits, Allocator > SingleStringStream; - typedef std::basic_string< wchar_t, std::char_traits, Allocator > String; - typedef std::basic_ostringstream< wchar_t, std::char_traits, Allocator > StringStream; - - const std::basic_string< wchar_t, std::char_traits, Allocator > EmptyString; - + typedef std::basic_string< char, std::char_traits, LuceneAllocator > SingleString; + typedef std::basic_ostringstream< char, std::char_traits, LuceneAllocator > SingleStringStream; + typedef std::basic_string< wchar_t, std::char_traits, LuceneAllocator > String; + typedef std::basic_ostringstream< wchar_t, std::char_traits, LuceneAllocator > StringStream; + + const std::basic_string< wchar_t, std::char_traits, LuceneAllocator > EmptyString; + typedef boost::shared_ptr filelockPtr; typedef boost::shared_ptr threadPtr; - + typedef boost::shared_ptr ofstreamPtr; typedef boost::shared_ptr ifstreamPtr; typedef boost::shared_ptr localePtr; @@ -87,7 +87,7 @@ namespace Lucene typedef Array LongArray; typedef Array CharArray; typedef Array DoubleArray; - + template struct luceneEquals { @@ -96,7 +96,7 @@ namespace Lucene return first ? first->equals(second) : (!first && !second); } }; - + template struct luceneEqualTo { @@ -107,7 +107,7 @@ namespace Lucene } const TYPE& equalType; }; - + template struct luceneWeakEquals { @@ -118,7 +118,7 @@ namespace Lucene return first.lock()->equals(second.lock()); } }; - + template struct luceneHash : std::unary_function { @@ -127,7 +127,7 @@ namespace Lucene return type ? type->hashCode() : 0; } }; - + template struct luceneWeakHash : std::unary_function { @@ -136,7 +136,7 @@ namespace Lucene return type.expired() ? 0 : type.lock()->hashCode(); } }; - + template struct luceneCompare { @@ -149,14 +149,14 @@ namespace Lucene return (first->compareTo(second) < 0); } }; - + typedef boost::blank VariantNull; typedef boost::variant FieldsData; typedef boost::variant ComparableValue; typedef boost::variant NumericValue; typedef boost::variant StringValue; typedef boost::variant, Collection, Collection, VariantNull> CollectionValue; - + typedef HashSet< SegmentInfoPtr, luceneHash, luceneEquals > SetSegmentInfo; typedef HashSet< MergeThreadPtr, luceneHash, luceneEquals > SetMergeThread; typedef HashSet< OneMergePtr, luceneHash, luceneEquals > SetOneMerge; @@ -165,7 +165,7 @@ namespace Lucene typedef HashSet< BooleanClausePtr, luceneHash, luceneEquals > SetBooleanClause; typedef HashSet< ReaderFieldPtr, luceneHash, luceneEquals > SetReaderField; typedef HashSet SetByteArray; - + typedef HashMap< String, String > MapStringString; typedef HashMap< wchar_t, NormalizeCharMapPtr > MapCharNormalizeCharMap; typedef HashMap< String, AnalyzerPtr > MapStringAnalyzer; @@ -186,7 +186,7 @@ namespace Lucene typedef HashMap< String, double > MapStringDouble; typedef HashMap< int32_t, CachePtr > MapStringCache; typedef HashMap< String, LockPtr > MapStringLock; - + typedef HashMap< SegmentInfoPtr, SegmentReaderPtr, luceneHash, luceneEquals > MapSegmentInfoSegmentReader; typedef HashMap< SegmentInfoPtr, int32_t, luceneHash, luceneEquals > MapSegmentInfoInt; typedef HashMap< DocFieldConsumerPerThreadPtr, Collection, luceneHash, luceneEquals > MapDocFieldConsumerPerThreadCollectionDocFieldConsumerPerField; @@ -200,17 +200,17 @@ namespace Lucene typedef HashMap< EntryPtr, boost::any, luceneHash, luceneEquals > MapEntryAny; typedef HashMap< PhrasePositionsPtr, LuceneObjectPtr, luceneHash, luceneEquals > MapPhrasePositionsLuceneObject; typedef HashMap< ReaderFieldPtr, SetReaderField, luceneHash, luceneEquals > MapReaderFieldSetReaderField; - + typedef WeakHashMap< LuceneObjectWeakPtr, LuceneObjectPtr, luceneWeakHash, luceneWeakEquals > WeakMapObjectObject; typedef WeakHashMap< LuceneObjectWeakPtr, MapEntryAny, luceneWeakHash, luceneWeakEquals > WeakMapLuceneObjectMapEntryAny; - + typedef Map< String, AttributePtr > MapStringAttribute; typedef Map< int64_t, DocumentsWriterThreadStatePtr > MapThreadDocumentsWriterThreadState; typedef Map< String, IndexReaderPtr > MapStringIndexReader; typedef Map< TermPtr, NumPtr, luceneCompare > MapTermNum; - + typedef boost::function TermVectorEntryComparator; - + template < class KEY, class VALUE, class HASH = boost::hash, class EQUAL = std::equal_to > class SimpleLRUCache; typedef SimpleLRUCache< TermPtr, TermInfoPtr, luceneHash, luceneEquals > TermInfoCache; typedef boost::shared_ptr TermInfoCachePtr; diff --git a/include/Allocator.h b/include/LuceneAllocator.h similarity index 62% rename from include/Allocator.h rename to include/LuceneAllocator.h index 4c356feb..41240da2 100644 --- a/include/Allocator.h +++ b/include/LuceneAllocator.h @@ -13,24 +13,26 @@ namespace Lucene { /// Allocate block of memory. LPPAPI void* AllocMemory(size_t size); - + /// Reallocate a given block of memory. LPPAPI void* ReallocMemory(void* memory, size_t size); - + /// Release a given block of memory. LPPAPI void FreeMemory(void* memory); - + /// Release thread cache. Note: should be called whenever a thread /// exits and using nedmalloc. LPPAPI void ReleaseThreadCache(); - + + #ifdef LPP_USE_ALLOCATOR + /// Custom stl allocator used to help exporting stl container across process /// borders. It can also calls custom memory allocation functions that can /// help track memory leaks and/or improve performance over standard allocators. /// @see #AllocMemory(size_t) /// @see #FreeMemory(void*) template - class Allocator + class LuceneAllocator { public: typedef size_t size_type; @@ -41,106 +43,112 @@ namespace Lucene typedef const TYPE& const_reference; typedef TYPE value_type; - Allocator() + LuceneAllocator() { } - - Allocator(const Allocator&) + + LuceneAllocator(const LuceneAllocator&) { } - pointer allocate(size_type n, const void* = 0) + pointer allocate(size_type n, const void* = 0) { return (TYPE*)AllocMemory((size_t)(n * sizeof(TYPE))); } - void deallocate(void* p, size_type) + void deallocate(void* p, size_type) { - if (p != NULL) + if (p != NULL) FreeMemory(p); } - pointer address(reference x) const - { - return &x; + pointer address(reference x) const + { + return &x; } - const_pointer address(const_reference x) const - { - return &x; + const_pointer address(const_reference x) const + { + return &x; } - Allocator& operator= (const Allocator&) - { - return *this; + LuceneAllocator& operator= (const LuceneAllocator&) + { + return *this; } void construct(pointer p, const TYPE& val) { - new ((TYPE*)p) TYPE(val); + new ((TYPE*)p) TYPE(val); } - void destroy(pointer p) - { + void destroy(pointer p) + { p->~TYPE(); } - size_type max_size() const - { - return size_t(-1); + size_type max_size() const + { + return size_t(-1); } template - struct rebind - { - typedef Allocator other; + struct rebind + { + typedef LuceneAllocator other; }; template - Allocator(const Allocator&) + LuceneAllocator(const LuceneAllocator&) { } }; template - inline bool operator== (const Allocator&, const Allocator&) - { - return true; + inline bool operator== (const LuceneAllocator&, const LuceneAllocator&) + { + return true; } - + template - inline bool operator!= (const Allocator&, const Allocator&) - { - return false; + inline bool operator!= (const LuceneAllocator&, const LuceneAllocator&) + { + return false; } template <> - class Allocator + class LuceneAllocator { public: typedef void* pointer; typedef const void* const_pointer; typedef void value_type; - Allocator() + LuceneAllocator() { } - - Allocator(const Allocator&) + + LuceneAllocator(const LuceneAllocator&) { } template - struct rebind - { - typedef Allocator other; + struct rebind + { + typedef LuceneAllocator other; }; template - Allocator(const Allocator&) + LuceneAllocator(const LuceneAllocator&) { } }; + + #endif } +#ifndef LPP_USE_ALLOCATOR +#define LuceneAllocator std::allocator +#endif + #endif diff --git a/include/LuceneFactory.h b/include/LuceneFactory.h index 6424d2a0..7e4f817c 100644 --- a/include/LuceneFactory.h +++ b/include/LuceneFactory.h @@ -18,7 +18,7 @@ namespace Lucene #if BOOST_VERSION <= 103800 return boost::shared_ptr(new T); #else - return boost::allocate_shared(Allocator()); + return boost::allocate_shared(LuceneAllocator()); #endif } @@ -28,7 +28,7 @@ namespace Lucene #if BOOST_VERSION <= 103800 return boost::shared_ptr(new T(a1)); #else - return boost::allocate_shared(Allocator(), a1); + return boost::allocate_shared(LuceneAllocator(), a1); #endif } @@ -38,7 +38,7 @@ namespace Lucene #if BOOST_VERSION <= 103800 return boost::shared_ptr(new T(a1, a2)); #else - return boost::allocate_shared(Allocator(), a1, a2); + return boost::allocate_shared(LuceneAllocator(), a1, a2); #endif } @@ -48,7 +48,7 @@ namespace Lucene #if BOOST_VERSION <= 103800 return boost::shared_ptr(new T(a1, a2, a3)); #else - return boost::allocate_shared(Allocator(), a1, a2, a3); + return boost::allocate_shared(LuceneAllocator(), a1, a2, a3); #endif } @@ -58,7 +58,7 @@ namespace Lucene #if BOOST_VERSION <= 103800 return boost::shared_ptr(new T(a1, a2, a3, a4)); #else - return boost::allocate_shared(Allocator(), a1, a2, a3, a4); + return boost::allocate_shared(LuceneAllocator(), a1, a2, a3, a4); #endif } @@ -68,7 +68,7 @@ namespace Lucene #if BOOST_VERSION <= 103800 return boost::shared_ptr(new T(a1, a2, a3, a4, a5)); #else - return boost::allocate_shared(Allocator(), a1, a2, a3, a4, a5); + return boost::allocate_shared(LuceneAllocator(), a1, a2, a3, a4, a5); #endif } @@ -78,7 +78,7 @@ namespace Lucene #if BOOST_VERSION <= 103800 return boost::shared_ptr(new T(a1, a2, a3, a4, a5, a6)); #else - return boost::allocate_shared(Allocator(), a1, a2, a3, a4, a5, a6); + return boost::allocate_shared(LuceneAllocator(), a1, a2, a3, a4, a5, a6); #endif } @@ -88,7 +88,7 @@ namespace Lucene #if BOOST_VERSION <= 103800 return boost::shared_ptr(new T(a1, a2, a3, a4, a5, a6, a7)); #else - return boost::allocate_shared(Allocator(), a1, a2, a3, a4, a5, a6, a7); + return boost::allocate_shared(LuceneAllocator(), a1, a2, a3, a4, a5, a6, a7); #endif } @@ -98,7 +98,7 @@ namespace Lucene #if BOOST_VERSION <= 103800 return boost::shared_ptr(new T(a1, a2, a3, a4, a5, a6, a7, a8)); #else - return boost::allocate_shared(Allocator(), a1, a2, a3, a4, a5, a6, a7, a8); + return boost::allocate_shared(LuceneAllocator(), a1, a2, a3, a4, a5, a6, a7, a8); #endif } @@ -108,7 +108,7 @@ namespace Lucene #if BOOST_VERSION <= 103800 return boost::shared_ptr(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9)); #else - return boost::allocate_shared(Allocator(), a1, a2, a3, a4, a5, a6, a7, a8, a9); + return boost::allocate_shared(LuceneAllocator(), a1, a2, a3, a4, a5, a6, a7, a8, a9); #endif } diff --git a/include/Map.h b/include/Map.h index db466e5c..c7dabcdf 100644 --- a/include/Map.h +++ b/include/Map.h @@ -19,19 +19,19 @@ namespace Lucene public: typedef Map this_type; typedef std::pair key_value; - typedef std::map< KEY, VALUE, LESS, Allocator > map_type; + typedef std::map< KEY, VALUE, LESS, LuceneAllocator > map_type; typedef typename map_type::iterator iterator; typedef typename map_type::const_iterator const_iterator; typedef KEY key_type; typedef VALUE value_type; - + virtual ~Map() { } - + protected: boost::shared_ptr mapContainer; - + public: static this_type newInstance() { @@ -39,108 +39,108 @@ namespace Lucene instance.mapContainer = Lucene::newInstance(); return instance; } - + void reset() { mapContainer.reset(); } - + int32_t size() const { return (int32_t)mapContainer->size(); } - + bool empty() const { return mapContainer->empty(); } - + void clear() { mapContainer->clear(); } - + iterator begin() { return mapContainer->begin(); } - + iterator end() { return mapContainer->end(); } - + const_iterator begin() const { return mapContainer->begin(); } - + const_iterator end() const { return mapContainer->end(); } - + operator bool() const { return mapContainer; } - + bool operator! () const { return !mapContainer; } - + map_type& operator= (const map_type& other) { mapContainer = other.mapContainer; return *this; } - + void put(const KEY& key, const VALUE& value) { (*mapContainer)[key] = value; } - + template void putAll(ITER first, ITER last) { for (iterator current = first; current != last; ++current) (*mapContainer)[current->first] = current->second; } - + template void remove(ITER pos) { mapContainer->erase(pos); } - + template ITER remove(ITER first, ITER last) { return mapContainer->erase(first, last); } - + bool remove(const KEY& key) { return (mapContainer->erase(key) > 0); } - + iterator find(const KEY& key) { return mapContainer->find(key); } - + VALUE get(const KEY& key) const { iterator findValue = mapContainer->find(key); return findValue == mapContainer->end() ? VALUE() : findValue->second; } - + bool contains(const KEY& key) const { return (mapContainer->find(key) != mapContainer->end()); } - + VALUE& operator[] (const KEY& key) { return (*mapContainer)[key]; diff --git a/include/PriorityQueue.h b/include/PriorityQueue.h index fb67bb03..318e1df2 100644 --- a/include/PriorityQueue.h +++ b/include/PriorityQueue.h @@ -12,7 +12,7 @@ namespace Lucene { - /// A PriorityQueue maintains a partial ordering of its elements such that the least element can always + /// A PriorityQueue maintains a partial ordering of its elements such that the least element can always /// be found in constant time. Put()'s and pop()'s require log(size) time. /// /// NOTE: This class pre-allocates a full array of length maxSize + 1. @@ -20,14 +20,14 @@ namespace Lucene class PriorityQueue : public LuceneObject { public: - typedef typename std::vector< TYPE, Allocator > heap_type; - + typedef typename std::vector< TYPE, LuceneAllocator > heap_type; + PriorityQueue(int32_t maxSize) { this->_size = 0; this->_maxSize = maxSize; } - + virtual ~PriorityQueue() { } @@ -36,12 +36,12 @@ namespace Lucene heap_type heap; int32_t _size; int32_t _maxSize; - + public: virtual void initialize() { bool empty = heap.empty(); - + if (empty) { int32_t heapSize = 0; @@ -53,8 +53,8 @@ namespace Lucene else if (_maxSize == INT_MAX) { // Don't wrap heapSize to -1, in this case, which causes a confusing NegativeArraySizeException. - // Note that very likely this will simply then hit an OOME, but at least that's more indicative - // to caller that this values is too big. We don't +1 in this case, but it's very unlikely in + // Note that very likely this will simply then hit an OOME, but at least that's more indicative + // to caller that this values is too big. We don't +1 in this case, but it's very unlikely in // practice one will actually insert this many objects into the PQ heapSize = INT_MAX; } @@ -65,7 +65,7 @@ namespace Lucene } this->heap.resize(heapSize); } - + // If sentinel objects are supported, populate the queue with them TYPE sentinel = getSentinelObject(); if (empty && sentinel) @@ -76,14 +76,14 @@ namespace Lucene _size = _maxSize; } } - + /// Return maximum size of queue int32_t maxSize() { return _maxSize; } - - /// Adds an Object to a PriorityQueue in log(size) time. If one tries to add more objects + + /// Adds an Object to a PriorityQueue in log(size) time. If one tries to add more objects /// than maxSize from initialize an {@link IndexOutOfBoundsException} is thrown. TYPE add(const TYPE& type) { @@ -94,10 +94,10 @@ namespace Lucene upHeap(); return heap[1]; } - - /// Adds an Object to a PriorityQueue in log(size) time. It returns the object (if any) that was - /// dropped off the heap because it was full. This can be the given parameter (in case it is - /// smaller than the full heap's minimum, and couldn't be added), or another object that was + + /// Adds an Object to a PriorityQueue in log(size) time. It returns the object (if any) that was + /// dropped off the heap because it was full. This can be the given parameter (in case it is + /// smaller than the full heap's minimum, and couldn't be added), or another object that was /// previously the smallest value in the heap and now has been replaced by a larger one, or null /// if the queue wasn't yet full with maxSize elements. TYPE addOverflow(const TYPE& type) @@ -117,15 +117,15 @@ namespace Lucene else return type; } - + /// Returns the least element of the PriorityQueue. TYPE top() { - // We don't need to check size here: if maxSize is 0, then heap is length 2 array with both + // We don't need to check size here: if maxSize is 0, then heap is length 2 array with both // entries null. If size is 0 then heap[1] is already null. return heap[1]; } - + /// Removes and returns the least element of the PriorityQueue. TYPE pop() { @@ -140,26 +140,26 @@ namespace Lucene else return TYPE(); } - + /// Should be called when the Object at top changes values. TYPE updateTop() { downHeap(); return heap[1]; } - + /// Returns the number of elements currently stored in the PriorityQueue. int32_t size() const { return _size; } - + /// Returns whether PriorityQueue is currently empty. bool empty() const { return (_size == 0); } - + /// Removes all entries from the PriorityQueue. void clear() { @@ -167,7 +167,7 @@ namespace Lucene heap[i] = TYPE(); _size = 0; } - + protected: void upHeap() { @@ -182,7 +182,7 @@ namespace Lucene } heap[i] = node; // install saved node } - + void downHeap() { int32_t i = 1; @@ -202,18 +202,18 @@ namespace Lucene } heap[i] = node; // install saved node } - + /// Determines the ordering of objects in this priority queue. Subclasses must define this one method. virtual bool lessThan(const TYPE& first, const TYPE& second) { return std::less()(first, second); } - - /// This method can be overridden by extending classes to return a sentinel object which will be used by - /// {@link #initialize} to fill the queue, so that the code which uses that queue can always assume it's + + /// This method can be overridden by extending classes to return a sentinel object which will be used by + /// {@link #initialize} to fill the queue, so that the code which uses that queue can always assume it's /// full and only change the top without attempting to insert any new object. /// - /// Those sentinel values should always compare worse than any non-sentinel value (ie., {@link #lessThan} + /// Those sentinel values should always compare worse than any non-sentinel value (ie., {@link #lessThan} /// should always favour the non-sentinel values). virtual TYPE getSentinelObject() { diff --git a/include/Set.h b/include/Set.h index 911c718a..bc62f170 100644 --- a/include/Set.h +++ b/include/Set.h @@ -18,18 +18,18 @@ namespace Lucene { public: typedef Set this_type; - typedef std::set< TYPE, LESS, Allocator > set_type; + typedef std::set< TYPE, LESS, LuceneAllocator > set_type; typedef typename set_type::iterator iterator; typedef typename set_type::const_iterator const_iterator; typedef TYPE value_type; - + virtual ~Set() { } - + protected: boost::shared_ptr setContainer; - + public: static this_type newInstance() { @@ -37,7 +37,7 @@ namespace Lucene instance.setContainer = Lucene::newInstance(); return instance; } - + template static this_type newInstance(ITER first, ITER last) { @@ -45,78 +45,78 @@ namespace Lucene instance.setContainer = Lucene::newInstance(first, last); return instance; } - + void reset() { setContainer.reset(); } - + int32_t size() const { return (int32_t)setContainer->size(); } - + bool empty() const { return setContainer->empty(); } - + void clear() { setContainer->clear(); } - + iterator begin() { return setContainer->begin(); } - + iterator end() { return setContainer->end(); } - + const_iterator begin() const { return setContainer->begin(); } - + const_iterator end() const { return setContainer->end(); } - + bool add(const TYPE& type) { return setContainer->insert(type).second; } - + template void addAll(ITER first, ITER last) { setContainer->insert(first, last); } - + bool remove(const TYPE& type) { return (setContainer->erase(type) > 0); } - + iterator find(const TYPE& type) { return setContainer->find(type); } - + bool contains(const TYPE& type) const { return (setContainer->find(type) != setContainer->end()); } - + bool equals(const this_type& other) const { return equals(other, std::equal_to()); } - + template bool equals(const this_type& other, PRED comp) const { @@ -124,27 +124,27 @@ namespace Lucene return false; return std::equal(setContainer->begin(), setContainer->end(), other.setContainer->begin(), comp); } - + void swap(this_type& other) { setContainer.swap(other->setContainer); } - + operator bool() const { return setContainer; } - + bool operator! () const { return !setContainer; } - + bool operator== (const this_type& other) { return (setContainer == other.setContainer); } - + bool operator!= (const this_type& other) { return (setContainer != other.setContainer); diff --git a/include/SimpleLRUCache.h b/include/SimpleLRUCache.h index 00542819..8b6ab822 100644 --- a/include/SimpleLRUCache.h +++ b/include/SimpleLRUCache.h @@ -22,18 +22,18 @@ namespace Lucene typedef std::pair key_value; typedef std::list< key_value > key_list; typedef typename key_list::const_iterator const_iterator; - typedef boost::unordered_map< KEY, typename key_list::iterator, HASH, EQUAL, Allocator< std::pair > > map_type; + typedef boost::unordered_map< KEY, typename key_list::iterator, HASH, EQUAL, LuceneAllocator< std::pair > > map_type; typedef typename map_type::const_iterator map_iterator; - + SimpleLRUCache(int32_t cacheSize) { this->cacheSize = cacheSize; } - + virtual ~SimpleLRUCache() { } - + protected: int32_t cacheSize; key_list cacheList; @@ -44,38 +44,38 @@ namespace Lucene { cacheList.push_front(std::make_pair(key, value)); cacheMap[key] = cacheList.begin(); - + if ((int32_t)cacheList.size() > cacheSize) { cacheMap.erase(cacheList.back().first); cacheList.pop_back(); } } - + VALUE get(const KEY& key) { map_iterator find = cacheMap.find(key); if (find == cacheMap.end()) return VALUE(); - + VALUE value(find->second->second); cacheList.erase(find->second); cacheList.push_front(std::make_pair(key, value)); cacheMap[key] = cacheList.begin(); - + return value; } - + bool contains(const KEY& key) const { return (cacheMap.find(key) != cacheMap.end()); } - + int32_t size() const { return (int32_t)cacheList.size(); } - + const_iterator begin() const { return cacheList.begin(); diff --git a/src/core/msvc/lucene++.vcproj b/src/core/msvc/lucene++.vcproj index 0a415bf4..390c7bb6 100644 --- a/src/core/msvc/lucene++.vcproj +++ b/src/core/msvc/lucene++.vcproj @@ -3520,11 +3520,11 @@ Name="platform" >