Browse Source

Updated tinystl.

Branimir Karadžić 10 years ago
parent
commit
bbff83fe62

+ 3 - 0
include/tinystl/hash_base.h

@@ -84,6 +84,9 @@ namespace tinystl {
 		const Key first;
 		unordered_hash_node* next;
 		unordered_hash_node* prev;
+
+	private:
+		unordered_hash_node& operator=(const unordered_hash_node&);
 	};
 
 	template<typename Key>

+ 3 - 3
include/tinystl/unordered_set.h

@@ -81,12 +81,12 @@ namespace tinystl {
 	{
 		const size_t nbuckets = (size_t)(other.m_buckets.last - other.m_buckets.first);
 		buffer_init<pointer, Alloc>(&m_buckets);
-		buffer_resize<pointer, Alloc>(&m_buckets, 9, 0);
+		buffer_resize<pointer, Alloc>(&m_buckets, nbuckets, 0);
 
-		for (pointer* it = *other.m_buckets.first; it; it = it->next) {
+		for (pointer it = *other.m_buckets.first; it; it = it->next) {
 			unordered_hash_node<Key, void>* newnode = new(placeholder(), Alloc::static_allocate(sizeof(unordered_hash_node<Key, void>))) unordered_hash_node<Key, void>(*it);
 			newnode->next = newnode->prev = 0;
-			unordered_hash_node_insert(newnode, hash(*it), m_buckets.first, nbuckets - 1);
+			unordered_hash_node_insert(newnode, hash(it->first), m_buckets.first, nbuckets - 1);
 		}
 	}
 

+ 43 - 0
tests/unordered_set_copyctor.cpp

@@ -0,0 +1,43 @@
+/*-
+* Copyright 2012-2015 Matthew Endsley
+* All rights reserved
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted providing that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "test.h"
+
+#include <tinystl/allocator.h>
+#include <tinystl/unordered_set.h>
+#include <UnitTest++.h>
+
+TEST(uoset_copyctor) {
+
+	// verify this compiles
+	typedef tinystl::unordered_set<unsigned int> set;
+	set s;
+	s.insert(32);
+	set other = s;
+	CHECK(other.find(32) != other.end());
+	other.clear();
+	CHECK(other.empty());
+}

+ 39 - 0
tests/unordered_set_pod.cpp

@@ -0,0 +1,39 @@
+/*-
+* Copyright 2012-2015 Matthew Endsley
+* All rights reserved
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted providing that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "test.h"
+
+#include <tinystl/allocator.h>
+#include <tinystl/unordered_set.h>
+#include <UnitTest++.h>
+
+TEST(uoset_pod_compiles) {
+
+	// verify this compiles
+	tinystl::unordered_set<unsigned int> s;
+	s.insert(32);
+	s.clear();
+}