4#include "core/builtin/container/iter/biter.inl"
5#include "core/builtin/container/native/tnarr.inl"
10#define TEMPL template <typename K, typename V>
11#define ME tbicontainable<K, V>
14 ME::~tbicontainable() {}
17 V& ME::operator[](
const K& key) {
return *get(key); }
20 const V& ME::operator[](
const K& key)
const {
return *get(key); }
23 ncnt ME::isEmpty()
const {
return len() <= 0; }
26 nbool ME::in(
const V& val)
const {
27 return get([&](
const K&,
const V& elem) {
return &elem == &val; });
31 nbool ME::in(std::function<nbool(
const K& key,
const V& val)> l)
const {
return in<V>(l); }
34 template <
typename V1> nbool ME::in(std::function<nbool(
const K& key,
const V1& val)> l)
const {
35 for(
auto e = begin(); e; ++e) {
36 V1& val = e->template cast<V1>() OR_CONTINUE;
37 const K& key = e.getKey() OR_CONTINUE;
38 WHEN(l(key, val)) .ret(true);
44 template <typename V1> V1* ME::get() {
45 return get<V1>([](
const K&,
const V1&) {
return true; });
49 template <
typename V1> V1* ME::get(
const K& key) {
return get(key) TO(
template cast<V1>()); }
52 template <
typename V1> V1* ME::get(std::function<nbool(
const K&,
const V1&)> l) {
53 for(
auto e = begin(); e; ++e) {
54 V1& val = e.getVal() TO(
template cast<V1>()) OR_CONTINUE;
55 const K& key = e.getKey() OR_CONTINUE;
56 if(!l(key, val)) continue;
64 V* ME::get(std::function<nbool(const K&, const V&)> l) {
return this->get<V>(l); }
67 tnarr<V> ME::getAll(
const K& key)
const {
74 template <
typename V1> tnarr<V1> ME::getAll()
const {
75 return getAll<V1>([](
const K&,
const V1&) {
return true; });
79 template <
typename V1> tnarr<V1> ME::getAll(std::function<nbool(
const K&,
const V1&)> l)
const {
81 for(
auto e = begin(); e; ++e) {
82 const V1& val = e.getVal() TO(
template cast<V1>()) OR_CONTINUE;
83 const K& key = e.getKey() OR_CONTINUE;
84 if(!l(key, val)) continue;
93 tnarr<V> ME::getAll(std::function<nbool(const K&, const V&)> l)
const {
return this->getAll<V>(l); }
96 template <
typename V1>
void ME::each(std::function<nbool(
const K&, V1&)> l) {
97 for(
auto e = begin(); e; ++e) {
98 V1& val = e.getVal() TO(
template cast<V1>()) OR_CONTINUE;
99 const K& key = e.getKey() OR_CONTINUE;
100 if(!l(key, val)) break;
105 void ME::each(std::function<nbool(const K&, V&)> l) { this->each<V>(l); }
108 typename ME::iter ME::begin()
const {
return iterate(0,
true); }
111 typename ME::iter ME::begin(
const K& key)
const {
return iterate(key,
true); }
114 typename ME::iter ME::rbegin()
const {
return riterate(0,
true); }
117 typename ME::iter ME::rbegin(
const K& key)
const {
return riterate(key,
true); }
120 typename ME::iter ME::end()
const {
return iterate(len(),
true); }
123 typename ME::iter ME::rend()
const {
return riterate(len(),
true); }
126 typename ME::iter ME::last()
const {
return iterate(len() - 1); }
129 typename ME::iter ME::iterate(ncnt step)
const {
return iterate(step,
false); }
132 typename ME::iter ME::iterate(ncnt step, nbool isBoundary)
const {
133 return iter(_onMakeIteration(
nullptr,
false, step, isBoundary));
137 typename ME::iter ME::iterate(
const K& key)
const {
return iterate(key,
false); }
140 typename ME::iter ME::iterate(
const K& key, nbool isBoundary)
const {
141 auto* e = _onMakeIteration(&key,
false, 0, isBoundary);
142 const K* eKey = e->getKey();
143 if(!e->isEnd() && (!eKey || *eKey != key)) e->next(1);
149 typename ME::iter ME::riterate(ncnt step)
const {
return riterate(step,
false); }
152 typename ME::iter ME::riterate(ncnt step, nbool isBoundary)
const {
153 return iter(_onMakeIteration(
nullptr,
true, step, isBoundary));
157 typename ME::iter ME::riterate(
const K& key)
const {
return riterate(key,
false); }
160 typename ME::iter ME::riterate(
const K& key, nbool isBoundary)
const {
161 auto* e = _onMakeIteration(&key,
true, 0, isBoundary);
162 if(!e->isEnd() && *e->getKey() != key) e->next(1);
168 ncnt ME::add(
const iter& from,
const iter& to) {
170 for(
iter e = from; e != to; ++e)
171 if(add(e.getKey(), e.getVal())) ret++;
176 ncnt ME::add(
const tbicontainable& rhs) {
return add(rhs.begin(), rhs.end()); }
179 nbool ME::del(
const tbicontainable& rhs) {
return del(rhs.begin(), rhs.end()); }
Bidirectional iterator for key-value containers.
Definition biter.hpp:10