-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ordered container): ordered container & fix __bitree__::_S_check
- Loading branch information
Showing
7 changed files
with
297 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#ifndef _ASP_ORDERED_MAP_HPP_ | ||
#define _ASP_ORDERED_MAP_HPP_ | ||
|
||
#include <functional> | ||
|
||
#include "basic_param.hpp" | ||
#include "rb_tree.hpp" | ||
|
||
namespace asp { | ||
|
||
template <typename _Key, typename _Tp, | ||
typename _Compare = std::less<_Key>, | ||
typename _Alloc = std::allocator<std::pair<const _Key, _Tp>> | ||
> class ordered_map; | ||
|
||
template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> | ||
class ordered_map { | ||
typedef ordered_map<_Key, _Tp, _Compare, _Alloc> self; | ||
typedef rb_tree<_Key, std::pair<const _Key, _Tp>, _select_0x, true, _Compare, _Alloc> map_rbt; | ||
map_rbt _r; | ||
public: | ||
typedef typename map_rbt::key_type key_type; | ||
typedef typename map_rbt::value_type value_type; | ||
typedef typename map_rbt::mapped_type mapped_type; | ||
typedef typename map_rbt::key_compare key_compare; | ||
typedef typename map_rbt::iterator iterator; | ||
typedef typename map_rbt::const_iterator const_iterator; | ||
typedef typename map_rbt::ireturn_type ireturn_type; | ||
typedef typename map_rbt::insert_status insert_status; | ||
typedef typename map_rbt::ext_iterator ext_iterator; | ||
typedef typename map_rbt::ext_key ext_key; | ||
typedef typename map_rbt::ext_value ext_value; | ||
|
||
/// (de)constructor | ||
ordered_map() = default; | ||
ordered_map(const self& _x) : _r(_x._r) {} | ||
virtual ~ordered_map() = default; | ||
|
||
/// implement | ||
size_type size() const { return _r.size(); } | ||
bool empty() const { return _r.empty(); } | ||
iterator begin() { return _r.begin(); } | ||
iterator end() { return _r.end(); } | ||
const_iterator cbegin() const { return _r.cbegin(); } | ||
const_iterator cend() const { return _r.cend(); } | ||
ireturn_type insert(const value_type& _v) { return _r.insert(_v); } | ||
ireturn_type set(const key_type& _k, const mapped_type& _m) { return _r.insert(value_type(_k, _m)); } | ||
size_type erase(const key_type& _k) { return _r.erase(_k); } | ||
size_type count(const key_type& _k) const { return _r.count(_k); } | ||
void clear() { _r.clear(); } | ||
iterator find(const key_type& _k) { return _r.find(_k); } | ||
const_iterator find(const key_type& _k) const { return _r.find(_k); } | ||
#ifdef _CONTAINER_CHECK_ | ||
int check() const { return _r.check(); } | ||
#endif // _CONTAINER_CHECK_ | ||
|
||
/// output | ||
template <typename _K, typename _T, typename _C, typename _A> | ||
friend std::ostream& operator<<(std::ostream& os, const ordered_map<_K, _T, _C, _A>& _um); | ||
// friend std::ostream& operator<<(std::ostream& os, const const_iterator& _i); | ||
}; | ||
|
||
template <typename _Key, typename _Tp, typename _Comp, typename _Alloc> auto | ||
operator<<(std::ostream& os, const ordered_map<_Key, _Tp, _Comp, _Alloc>& _um) | ||
-> std::ostream& { | ||
os << _um._r; | ||
return os; | ||
}; | ||
|
||
}; | ||
|
||
#endif // _ASP_ORDERED_MAP_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#ifndef _ASP_ORDERED_MULTI_MAP_HPP_ | ||
#define _ASP_ORDERED_MULTI_MAP_HPP_ | ||
|
||
#include <functional> | ||
|
||
#include "basic_param.hpp" | ||
#include "rb_tree.hpp" | ||
|
||
namespace asp { | ||
|
||
template <typename _Key, typename _Tp, | ||
typename _Compare = std::less<_Key>, | ||
typename _Alloc = std::allocator<std::pair<const _Key, _Tp>> | ||
> class ordered_multimap; | ||
|
||
template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> | ||
class ordered_multimap { | ||
typedef ordered_multimap<_Key, _Tp, _Compare, _Alloc> self; | ||
typedef rb_tree<_Key, std::pair<const _Key, _Tp>, _select_0x, false, _Compare, _Alloc> mmap_rbt; | ||
mmap_rbt _r; | ||
public: | ||
typedef typename mmap_rbt::key_type key_type; | ||
typedef typename mmap_rbt::value_type value_type; | ||
typedef typename mmap_rbt::mapped_type mapped_type; | ||
typedef typename mmap_rbt::key_compare key_compare; | ||
typedef typename mmap_rbt::iterator iterator; | ||
typedef typename mmap_rbt::const_iterator const_iterator; | ||
typedef typename mmap_rbt::ireturn_type ireturn_type; | ||
typedef typename mmap_rbt::insert_status insert_status; | ||
typedef typename mmap_rbt::ext_iterator ext_iterator; | ||
typedef typename mmap_rbt::ext_key ext_key; | ||
typedef typename mmap_rbt::ext_value ext_value; | ||
|
||
/// (de)constructor | ||
ordered_multimap() = default; | ||
ordered_multimap(const self& _x) : _r(_x._r) {} | ||
virtual ~ordered_multimap() = default; | ||
|
||
/// implement | ||
size_type size() const { return _r.size(); } | ||
bool empty() const { return _r.empty(); } | ||
iterator begin() { return _r.begin(); } | ||
iterator end() { return _r.end(); } | ||
const_iterator cbegin() const { return _r.cbegin(); } | ||
const_iterator cend() const { return _r.cend(); } | ||
ireturn_type insert(const value_type& _v) { return _r.insert(_v); } | ||
ireturn_type set(const key_type& _k, const mapped_type& _m) { return _r.insert(value_type(_k, _m)); } | ||
size_type erase(const key_type& _k) { return _r.erase(_k); } | ||
size_type count(const key_type& _k) const { return _r.count(_k); } | ||
void clear() { _r.clear(); } | ||
iterator find(const key_type& _k) { return _r.find(_k); } | ||
const_iterator find(const key_type& _k) const { return _r.find(_k); } | ||
#ifdef _CONTAINER_CHECK_ | ||
int check() const { return _r.check(); } | ||
#endif // _CONTAINER_CHECK_ | ||
|
||
/// output | ||
template <typename _K, typename _T, typename _C, typename _A> | ||
friend std::ostream& operator<<(std::ostream& os, const ordered_multimap<_K, _T, _C, _A>& _um); | ||
// friend std::ostream& operator<<(std::ostream& os, const const_iterator& _i); | ||
}; | ||
|
||
template <typename _Key, typename _Tp, typename _Comp, typename _Alloc> auto | ||
operator<<(std::ostream& os, const ordered_multimap<_Key, _Tp, _Comp, _Alloc>& _um) | ||
-> std::ostream& { | ||
os << _um._r; | ||
return os; | ||
}; | ||
|
||
}; | ||
|
||
#endif // _ASP_ORDERED_MULTI_MAP_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#ifndef _ASP_ORDERED_MULTI_SET_HPP_ | ||
#define _ASP_ORDERED_MULTI_SET_HPP_ | ||
|
||
#include <functional> | ||
|
||
#include "basic_param.hpp" | ||
#include "rb_tree.hpp" | ||
|
||
namespace asp { | ||
|
||
template <typename _Tp, | ||
typename _Compare = std::less<_Tp>, | ||
typename _Alloc = std::allocator<_Tp> | ||
> class ordered_multiset; | ||
|
||
template <typename _Tp, typename _Compare, typename _Alloc> | ||
class ordered_multiset { | ||
typedef ordered_multiset<_Tp, _Compare, _Alloc> self; | ||
typedef rb_tree<_Tp, _Tp, _select_self, false, _Compare, _Alloc> mset_rbt; | ||
mset_rbt _r; | ||
public: | ||
typedef typename mset_rbt::key_type key_type; | ||
typedef typename mset_rbt::value_type value_type; | ||
typedef typename mset_rbt::mapped_type mapped_type; | ||
typedef typename mset_rbt::key_compare key_compare; | ||
typedef typename mset_rbt::iterator iterator; | ||
typedef typename mset_rbt::const_iterator const_iterator; | ||
typedef typename mset_rbt::ireturn_type ireturn_type; | ||
typedef typename mset_rbt::insert_status insert_status; | ||
typedef typename mset_rbt::ext_iterator ext_iterator; | ||
typedef typename mset_rbt::ext_key ext_key; | ||
typedef typename mset_rbt::ext_value ext_value; | ||
|
||
/// (de)constructor | ||
ordered_multiset() = default; | ||
ordered_multiset(const self& _x) : _r(_x._r) {} | ||
virtual ~ordered_multiset() = default; | ||
|
||
/// implement | ||
size_type size() const { return _r.size(); } | ||
bool empty() const { return _r.empty(); } | ||
iterator begin() { return _r.begin(); } | ||
iterator end() { return _r.end(); } | ||
const_iterator cbegin() const { return _r.cbegin(); } | ||
const_iterator cend() const { return _r.cend(); } | ||
ireturn_type insert(const value_type& _v) { return _r.insert(_v); } | ||
ireturn_type set(const key_type& _k, const mapped_type& _m) { return _r.insert(value_type(_k, _m)); } | ||
size_type erase(const key_type& _k) { return _r.erase(_k); } | ||
size_type count(const key_type& _k) const { return _r.count(_k); } | ||
void clear() { _r.clear(); } | ||
iterator find(const key_type& _k) { return _r.find(_k); } | ||
const_iterator find(const key_type& _k) const { return _r.find(_k); } | ||
#ifdef _CONTAINER_CHECK_ | ||
int check() const { return _r.check(); } | ||
#endif // _CONTAINER_CHECK_ | ||
|
||
/// output | ||
template <typename _T, typename _C, typename _A> | ||
friend std::ostream& operator<<(std::ostream& os, const ordered_multiset<_T, _C, _A>& _um); | ||
// friend std::ostream& operator<<(std::ostream& os, const const_iterator& _i); | ||
}; | ||
|
||
template <typename _Tp, typename _Comp, typename _Alloc> auto | ||
operator<<(std::ostream& os, const ordered_multiset<_Tp, _Comp, _Alloc>& _um) | ||
-> std::ostream& { | ||
os << _um._r; | ||
return os; | ||
}; | ||
|
||
}; | ||
|
||
#endif // _ASP_ORDERED_MULTI_SET_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#ifndef _ASP_ORDERED_SET_HPP_ | ||
#define _ASP_ORDERED_SET_HPP_ | ||
|
||
#include <functional> | ||
|
||
#include "basic_param.hpp" | ||
#include "rb_tree.hpp" | ||
|
||
namespace asp { | ||
|
||
template <typename _Tp, | ||
typename _Compare = std::less<_Tp>, | ||
typename _Alloc = std::allocator<_Tp> | ||
> class ordered_set; | ||
|
||
template <typename _Tp, typename _Compare, typename _Alloc> | ||
class ordered_set { | ||
typedef ordered_set<_Tp, _Compare, _Alloc> self; | ||
typedef rb_tree<_Tp, _Tp, _select_self, true, _Compare, _Alloc> set_rbt; | ||
set_rbt _r; | ||
public: | ||
typedef typename set_rbt::key_type key_type; | ||
typedef typename set_rbt::value_type value_type; | ||
typedef typename set_rbt::mapped_type mapped_type; | ||
typedef typename set_rbt::key_compare key_compare; | ||
typedef typename set_rbt::iterator iterator; | ||
typedef typename set_rbt::const_iterator const_iterator; | ||
typedef typename set_rbt::ireturn_type ireturn_type; | ||
typedef typename set_rbt::insert_status insert_status; | ||
typedef typename set_rbt::ext_iterator ext_iterator; | ||
typedef typename set_rbt::ext_key ext_key; | ||
typedef typename set_rbt::ext_value ext_value; | ||
|
||
/// (de)constructor | ||
ordered_set() = default; | ||
ordered_set(const self& _x) : _r(_x._r) {} | ||
virtual ~ordered_set() = default; | ||
|
||
/// implement | ||
size_type size() const { return _r.size(); } | ||
bool empty() const { return _r.empty(); } | ||
iterator begin() { return _r.begin(); } | ||
iterator end() { return _r.end(); } | ||
const_iterator cbegin() const { return _r.cbegin(); } | ||
const_iterator cend() const { return _r.cend(); } | ||
ireturn_type insert(const value_type& _v) { return _r.insert(_v); } | ||
ireturn_type set(const key_type& _k, const mapped_type& _m) { return _r.insert(value_type(_k, _m)); } | ||
size_type erase(const key_type& _k) { return _r.erase(_k); } | ||
size_type count(const key_type& _k) const { return _r.count(_k); } | ||
void clear() { _r.clear(); } | ||
iterator find(const key_type& _k) { return _r.find(_k); } | ||
const_iterator find(const key_type& _k) const { return _r.find(_k); } | ||
#ifdef _CONTAINER_CHECK_ | ||
int check() const { return _r.check(); } | ||
#endif // _CONTAINER_CHECK_ | ||
|
||
/// output | ||
template <typename _T, typename _C, typename _A> | ||
friend std::ostream& operator<<(std::ostream& os, const ordered_set<_T, _C, _A>& _um); | ||
// friend std::ostream& operator<<(std::ostream& os, const const_iterator& _i); | ||
}; | ||
|
||
template <typename _Tp, typename _Comp, typename _Alloc> auto | ||
operator<<(std::ostream& os, const ordered_set<_Tp, _Comp, _Alloc>& _um) | ||
-> std::ostream& { | ||
os << _um._r; | ||
return os; | ||
}; | ||
|
||
}; | ||
|
||
#endif // _ASP_ORDERED_SET_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters