Commit 174ca03a authored by account-login's avatar account-login Committed by GitHub

Add some missing functions to libcpp maps and string (GH-4395)

* add swap() to libcpp.string
* add load_factor() to libcpp.unordered_map and libcpp.unordered_set
parent 42a4af2f
......@@ -62,6 +62,7 @@ cdef extern from "<string>" namespace "std" nogil:
void resize(size_t) except +
void resize(size_t, char) except +
void shrink_to_fit() except +
void swap(string& other)
size_t capacity()
void reserve(size_t) except +
void clear()
......
......@@ -66,6 +66,7 @@ cdef extern from "<unordered_map>" namespace "std" nogil:
#value_compare value_comp()
void max_load_factor(float)
float max_load_factor()
float load_factor()
void rehash(size_t)
void reserve(size_t)
size_t bucket_count()
......
......@@ -51,6 +51,7 @@ cdef extern from "<unordered_set>" namespace "std" nogil:
#value_compare value_comp()
void max_load_factor(float)
float max_load_factor()
float load_factor()
void rehash(size_t)
void reserve(size_t)
size_t bucket_count()
......@@ -110,6 +111,7 @@ cdef extern from "<unordered_set>" namespace "std" nogil:
#value_compare value_comp()
void max_load_factor(float)
float max_load_factor()
float load_factor()
void rehash(size_t)
void reserve(size_t)
size_t bucket_count()
......
......@@ -137,6 +137,7 @@ def test_unordered_set_functionality():
int_set.bucket_count()
int_set.max_bucket_count()
int_set.bucket(3)
assert int_set.load_factor() > 0
return "pass"
......@@ -187,6 +188,7 @@ def test_unordered_map_functionality():
int_map.bucket_count()
int_map.max_bucket_count()
int_map.bucket(3)
assert int_map.load_factor() > 0
intptr_map[0] = NULL
intptr = intptr_map.const_at(0)
......
......@@ -104,3 +104,12 @@ def test_unordered_multiset_find_erase(vals, to_remove):
it = ms.find(to_remove)
ms.erase(it)
return sorted([ item for item in ms ])
def test_unordered_multiset_misc():
"""
>>> test_unordered_multiset_misc()
"""
cdef unordered_multiset[int] ms = unordered_multiset[int]()
ms.insert(1)
assert ms.load_factor() > 0
......@@ -438,6 +438,16 @@ def test_stof(char *a):
return stof(s)
def test_swap():
"""
>>> test_swap()
"""
cdef string s1 = b_asdf, s_asdf = b_asdf
cdef string s2 = b_asdg, s_asdg = b_asdg
s1.swap(s2)
assert s1 == s_asdg and s2 == s_asdf
_WARNINGS = """
21:31: Cannot pass Python object as C++ data structure reference (string &), will pass by copy.
"""
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment