Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c0091fe
Add stxxl::vector::emplace_back()
michitux Jan 17, 2018
8191aed
Make vector movable
michitux Feb 15, 2017
0b313c1
Extend tests of vector move
michitux Feb 15, 2017
517ea74
deque: add emplace_front() and emplace_back() including tests
michitux Jan 17, 2018
f5a5a27
deque: add move constructor and move assignment operator
michitux Jan 17, 2018
e1f278c
btree: add emplace and emplace_hint
michitux Jan 17, 2018
0edcea3
btree: implement at
michitux Jan 17, 2018
05e386c
test_btree_insert_erase: use stxxl::comparator
michitux Jan 17, 2018
caadc61
test_btree_insert_erase: Fix typo in message
michitux Jan 17, 2018
6c522a9
map: implement emplace and emplace_hint
michitux Jan 17, 2018
81d174a
map: implement at
michitux Jan 17, 2018
98e067f
test_map_random: do not shadow local variable
michitux Jan 17, 2018
0102004
test_map: use comparator
michitux Jan 17, 2018
ef3f83e
vector: add push_back with rvalue reference
michitux Jan 17, 2018
ea7096c
queue: implement push with rvalue reference and emplace
michitux Jan 17, 2018
8cbc103
stack: emplace/insert: use proper forwarding
michitux Jan 17, 2018
edf2140
btree: implement C+11 insert/emplace interface with forwarding
michitux Jan 17, 2018
e1c9890
map: add (hopefully all) missing insert variants for C++11
michitux Jan 17, 2018
6e94b7f
stack: added push with rvalue reference and emplace for all types
michitux Jan 17, 2018
696cf2b
stack: add move construction and move assignment where possible
michitux Jan 17, 2018
eb9a7bf
btree: Add missing forward in insert
michitux Jan 17, 2018
c23fa0a
Merge branch 'master' into c++11_containers
michitux Jan 19, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 66 additions & 3 deletions include/stxxl/bits/containers/btree/btree.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,32 @@ class btree
}

std::pair<iterator, bool> insert(const value_type& x)
{
return insert_impl(x);
}

std::pair<iterator, bool> insert(value_type&& x)
{
return insert_impl(std::forward<value_type>(x));
}

void insert(std::initializer_list<value_type> ilist)
{
for (auto&& val : ilist)
{
insert_impl(std::forward<decltype(val)>(val));
}
}

template <class... Args>
std::pair<iterator, bool> emplace(Args&&... args)
{
return insert_impl(value_type(std::forward<Args>(args)...));
}

private:
template <typename V>
std::pair<iterator, bool> insert_impl(V&& x)
{
root_node_iterator_type it = m_root_node.lower_bound(x.first);
assert(!m_root_node.empty());
Expand All @@ -519,7 +545,7 @@ class btree
leaf_type* leaf = m_leaf_cache.get_node((leaf_bid_type)it->second, true);
assert(leaf);
std::pair<key_type, leaf_bid_type> splitter;
std::pair<iterator, bool> result = leaf->insert(x, splitter);
std::pair<iterator, bool> result = leaf->insert(std::forward<V>(x), splitter);
if (result.second)
++m_size;

Expand All @@ -544,7 +570,7 @@ class btree
node_type* node = m_node_cache.get_node((node_bid_type)it->second, true);
assert(node);
std::pair<key_type, node_bid_type> splitter;
std::pair<iterator, bool> result = node->insert(x, m_height - 1, splitter);
std::pair<iterator, bool> result = node->insert(std::forward<V>(x), m_height - 1, splitter);
if (result.second)
++m_size;

Expand All @@ -565,6 +591,7 @@ class btree
return result;
}

public:
iterator begin()
{
root_node_iterator_type it = m_root_node.begin();
Expand Down Expand Up @@ -635,6 +662,36 @@ class btree
return (*((insert(value_type(k, data_type()))).first)).second;
}

//! Returns a reference to the mapped value of the element with
//! key equivalent to key. If no such element exists, an exception
//! of type std::out_of_range is thrown.
data_type& at(const key_type& k)
{
iterator it = find(k);

if (UNLIKELY(it == end()))
{
throw std::out_of_range("stxxl::btree");
}

return it->second;
}

//! Returns a reference to the mapped value of the element with
//! key equivalent to key. If no such element exists, an exception
//! of type std::out_of_range is thrown.
const data_type& at(const key_type& k) const
{
const_iterator it = find(k);

if (UNLIKELY(it == end()))
{
throw std::out_of_range("stxxl::btree");
}

return it->second;
}

iterator find(const key_type& k)
{
root_node_iterator_type it = m_root_node.lower_bound(k);
Expand Down Expand Up @@ -948,12 +1005,18 @@ class btree
assert(size() == old_size - 1);
}

iterator insert(iterator /*pos*/, const value_type& x)
iterator insert(const_iterator /*pos*/, const value_type& x)
{
// pos ignored in the current version
return insert(x).first;
}

template <class... Args>
iterator emplace_hint(iterator hint, Args&&... args)
{
return insert(hint, value_type(std::forward<Args>(args)...));
}

void clear()
{
deallocate_children();
Expand Down
43 changes: 43 additions & 0 deletions include/stxxl/bits/containers/deque.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,22 @@ class deque
//! non-copyable: delete assignment operator
deque& operator = (const deque&) = delete;

//! move-constructor
deque(deque&& o) noexcept : deque() {
swap(o);
}

//! move assignment operator
deque& operator = (deque&& obj) noexcept
{
if (&obj != this)
{
deque tmp(std::forward<deque>(obj));
this->swap(tmp);
}
return *this;
}

~deque() // empty so far
{ }

Expand Down Expand Up @@ -618,6 +634,20 @@ class deque
++m_size;
}

template<class... Args>
void emplace_front(Args&&... args)
{
if ((m_begin + m_vector.size() - 1) % m_vector.size() == m_end)
{
// an overflow will occur: resize the array
double_array();
}

m_begin = (m_begin + m_vector.size() - 1) % m_vector.size();
m_vector[m_begin] = value_type(std::forward<Args>(args)...);
++m_size;
}

void push_back(const value_type& el)
{
if ((m_end + 1) % m_vector.size() == m_begin)
Expand All @@ -630,6 +660,19 @@ class deque
++m_size;
}

template<class... Args>
void emplace_back(Args&&... args)
{
if ((m_end + 1) % m_vector.size() == m_begin)
{
// an overflow will occur: resize the array
double_array();
}
m_vector[m_end] = value_type(std::forward<Args>(args)...);
m_end = (m_end + 1) % m_vector.size();
++m_size;
}

void pop_front()
{
assert(!empty());
Expand Down
47 changes: 46 additions & 1 deletion include/stxxl/bits/containers/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,34 @@ class map
{
return impl.insert(x);
}
iterator insert(iterator pos, const value_type& x)

std::pair<iterator, bool> insert(value_type&& value)
{
return impl.insert(std::forward<value_type>(value));
}

void insert(std::initializer_list<value_type> ilist)
{
return impl.insert(std::move(ilist));
}

template <class... Args>
std::pair<iterator, bool> emplace(Args&&... args)
{
return impl.emplace(std::forward<Args>(args)...);
}

iterator insert(const_iterator pos, const value_type& x)
{
return impl.insert(pos, x);
}

template <class... Args>
iterator emplace_hint(iterator hint, Args&&... args)
{
return impl.emplace_hint(hint, std::forward<Args>(args)...);
}

template <class InputIterator>
void insert(InputIterator b, InputIterator e)
{
Expand Down Expand Up @@ -312,6 +336,27 @@ class map

//! \}

//! \name Element access
//! \{

//! Returns a reference to the mapped value of the element with
//! key equivalent to key. If no such element exists, an exception
//! of type std::out_of_range is thrown.
data_type& at(const key_type& k)
{
return impl.at(k);
}

//! Returns a reference to the mapped value of the element with
//! key equivalent to key. If no such element exists, an exception
//! of type std::out_of_range is thrown.
const data_type& at(const key_type& k) const
{
return impl.at(k);
}

//! \}

//! \name Operators
//! \{

Expand Down
27 changes: 23 additions & 4 deletions include/stxxl/bits/containers/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,25 @@ class queue
//! \{

//! Adds an element in the queue.
void push(const value_type& val)
void push(const value_type& val) {
push_impl(val);
}

//! Adds an element in the queue.
void push(value_type&& val) {
push_impl(std::forward<value_type>(val));
}

//! Constructs and adds an element in the queue.
template <class... Args>
void emplace(Args&&... args) {
push_impl(value_type(std::forward<Args>(args)...));
}

private:
//! Adds an element in the queue. Generic implementation for all value types.
template <typename V>
void push_impl(V&& val)
{
if (TLX_UNLIKELY(back_element == back_block->begin() + (block_type::size - 1)))
{
Expand All @@ -244,7 +262,7 @@ class queue
back_element -= gap;

++back_element;
*back_element = val;
*back_element = std::forward<V>(val);
++m_size;
return;
}
Expand All @@ -268,14 +286,15 @@ class queue
back_block = pool->steal();

back_element = back_block->begin();
*back_element = val;
*back_element = std::forward<V>(val);
++m_size;
return;
}
++back_element;
*back_element = val;
*back_element = std::forward<V>(val);
++m_size;
}
public:

//! Removes element from the queue.
void pop()
Expand Down
Loading