mail[Wesnoth-commits] r36773 - in /trunk/src: skiplist.hpp skiplist_map.hpp skiplist_test.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by cjhopman on July 11, 2009 - 11:01:
Author: cjhopman
Date: Sat Jul 11 11:01:54 2009
New Revision: 36773

URL: http://svn.gna.org/viewcvs/wesnoth?rev=36773&view=rev
Log:
add operator==/!= for skiplist_map

Modified:
    trunk/src/skiplist.hpp
    trunk/src/skiplist_map.hpp
    trunk/src/skiplist_test.cpp

Modified: trunk/src/skiplist.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/skiplist.hpp?rev=36773&r1=36772&r2=36773&view=diff
==============================================================================
--- trunk/src/skiplist.hpp (original)
+++ trunk/src/skiplist.hpp Sat Jul 11 11:01:54 2009
@@ -19,7 +19,6 @@
 
 #include <cassert>
 #include <algorithm>
-#include <iostream>
 
 #include "ct_math.hpp"
 
@@ -122,18 +121,17 @@
 
 template <typename Alloc, typename Value, size_t Height>
 struct alloc_type_base : public alloc_type_base<Alloc, Value, Height - 1>,
-       public Alloc::template rebind<char[node_size<Value, node_base<Value>, 
Height>::value]>::other,
-       public Alloc::template rebind<node_base<Value>[Height]>::other
+       private Alloc::template rebind<char[node_size<Value, 
node_base<Value>, Height>::value]>::other,
+       private Alloc::template rebind<node_base<Value>[Height]>::other
 {
        typedef alloc_type_base<Alloc, Value, Height - 1> super;
        typedef typename Alloc::template rebind<char[node_size<Value, 
node_base<Value>, Height>::value]>::other node_alloc_type;
        typedef typename Alloc::template 
rebind<node_base<Value>[Height]>::other head_alloc_type;
 
        void* allocate_node(size_t h) {
-               if (h == Height) {
-                       std::cout << node_size<Value, node_base<Value>, 
Height>::value << std::endl;
+               if (h == Height)
                        return node_alloc_type::allocate(1);
-               }
+
                return super::allocate_node(h);
        }
 
@@ -174,8 +172,8 @@
 
 template <typename Value, typename Key, typename ExtractKey, typename 
Compare, typename Alloc>
 class skiplist :
-               alloc_type_base<Alloc, Value, SKIPLIST_MAX_HEIGHT>,
-               Compare
+               private alloc_type_base<Alloc, Value, SKIPLIST_MAX_HEIGHT>,
+               private Compare
 {
 public:
        typedef Key key_type;

Modified: trunk/src/skiplist_map.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/skiplist_map.hpp?rev=36773&r1=36772&r2=36773&view=diff
==============================================================================
--- trunk/src/skiplist_map.hpp (original)
+++ trunk/src/skiplist_map.hpp Sat Jul 11 11:01:54 2009
@@ -91,6 +91,14 @@
 
        allocator_type get_allocator() const { return super::get_allocator(); 
}
 
+       bool operator==(const skiplist_map& o) const {
+               return size() == o.size() && std::equal(begin(), end(), 
o.begin());
+       }
+
+       bool operator!=(const skiplist_map& o) const {
+               return !operator==(o);
+       }
+
        void swap(skiplist_map& o) {
                super::swap(o);
        }
@@ -102,7 +110,7 @@
 
 template <typename Key, typename Value, typename Compare, typename Alloc>
 bool operator==(const skiplist_map<Key, Value, Compare, Alloc>& a, const 
skiplist_map<Key, Value, Compare, Alloc>& b) {
-       return a.size() == b.size() && std::equal(a.begin(), a.end(), 
b.begin());
+       return a.operator==(b);
 }
 
 template <typename Key, typename Value, typename Compare, typename Alloc>

Modified: trunk/src/skiplist_test.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/skiplist_test.cpp?rev=36773&r1=36772&r2=36773&view=diff
==============================================================================
--- trunk/src/skiplist_test.cpp (original)
+++ trunk/src/skiplist_test.cpp Sat Jul 11 11:01:54 2009
@@ -7,6 +7,8 @@
 #include <map>
 #include <vector>
 #include <algorithm>
+
+#include <boost/pool/pool_alloc.hpp>
 
 #define FORMAT_ITER(x) x->first << ":" << x->second
 
@@ -243,7 +245,7 @@
 
 void test_map() {
        std::cout << "construct()" << std::endl;
-       typedef skiplist_map<int, std::string> slmap_t;
+       typedef skiplist_map<int, std::string, std::less<int>, 
boost::fast_pool_allocator<std::string> > slmap_t;
        slmap_t slmap;
        typedef std::map<int, std::string> stdmap_t;
        stdmap_t stdmap;
@@ -447,6 +449,14 @@
                assert(std::lexicographical_compare(stdrange.first, 
stdrange.second, slrange.first, slrange.second) == 0);
        }
 
+       std::cout << "operator==/operator!=" << std::endl;
+       {
+               slmap_t slmap2(slmap);
+               assert(slmap == slmap2);
+               slmap2.erase(slmap2.begin());
+               assert(slmap != slmap2);
+       }
+
 }
 
 int main() {




Related Messages


Powered by MHonArc, Updated Sat Jul 11 11:20:34 2009