forked from OctaForge/libostd
reduce code duplication
parent
ea70d2e467
commit
281371bb0c
|
@ -21,6 +21,21 @@ namespace detail {
|
||||||
HashChain<T> *next;
|
HashChain<T> *next;
|
||||||
T value;
|
T value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename R>
|
||||||
|
static inline octa::Size estimate_hrsize(const R &range,
|
||||||
|
octa::EnableIf<octa::IsFiniteRandomAccessRange<R>::value, bool> = true
|
||||||
|
) {
|
||||||
|
return range.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename R>
|
||||||
|
static inline octa::Size estimate_hrsize(const R &,
|
||||||
|
octa::EnableIf<!octa::IsFiniteRandomAccessRange<R>::value, bool> = true
|
||||||
|
) {
|
||||||
|
/* we have no idea how big the range actually is */
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
40
octa/map.h
40
octa/map.h
|
@ -51,21 +51,6 @@ private:
|
||||||
>;
|
>;
|
||||||
Base p_table;
|
Base p_table;
|
||||||
|
|
||||||
template<typename R>
|
|
||||||
octa::Size estimate_rsize(const R &range,
|
|
||||||
octa::EnableIf<octa::IsFiniteRandomAccessRange<R>::value, bool> = true
|
|
||||||
) {
|
|
||||||
return range.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename R>
|
|
||||||
octa::Size estimate_rsize(const R &,
|
|
||||||
octa::EnableIf<!octa::IsFiniteRandomAccessRange<R>::value, bool> = true
|
|
||||||
) {
|
|
||||||
/* we have no idea how big the range actually is */
|
|
||||||
return 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using Key = K;
|
using Key = K;
|
||||||
|
@ -110,7 +95,8 @@ public:
|
||||||
octa::IsConvertible<RangeReference<R>, Value>::value,
|
octa::IsConvertible<RangeReference<R>, Value>::value,
|
||||||
bool
|
bool
|
||||||
> = true
|
> = true
|
||||||
): p_table(size ? size : estimate_rsize(range), hf, eqf, alloc) {
|
): p_table(size ? size : octa::detail::estimate_hrsize(range),
|
||||||
|
hf, eqf, alloc) {
|
||||||
for (; !range.empty(); range.pop_front())
|
for (; !range.empty(); range.pop_front())
|
||||||
emplace(range.front());
|
emplace(range.front());
|
||||||
p_table.rehash_up();
|
p_table.rehash_up();
|
||||||
|
@ -152,7 +138,7 @@ public:
|
||||||
Map &
|
Map &
|
||||||
> operator=(R range) {
|
> operator=(R range) {
|
||||||
clear();
|
clear();
|
||||||
p_table.reserve_at_least(estimate_rsize(range));
|
p_table.reserve_at_least(octa::detail::estimate_hrsize(range));
|
||||||
for (; !range.empty(); range.pop_front())
|
for (; !range.empty(); range.pop_front())
|
||||||
emplace(range.front());
|
emplace(range.front());
|
||||||
p_table.rehash_up();
|
p_table.rehash_up();
|
||||||
|
@ -260,21 +246,6 @@ private:
|
||||||
>;
|
>;
|
||||||
Base p_table;
|
Base p_table;
|
||||||
|
|
||||||
template<typename R>
|
|
||||||
octa::Size estimate_rsize(const R &range,
|
|
||||||
octa::EnableIf<octa::IsFiniteRandomAccessRange<R>::value, bool> = true
|
|
||||||
) {
|
|
||||||
return range.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename R>
|
|
||||||
octa::Size estimate_rsize(const R &,
|
|
||||||
octa::EnableIf<!octa::IsFiniteRandomAccessRange<R>::value, bool> = true
|
|
||||||
) {
|
|
||||||
/* we have no idea how big the range actually is */
|
|
||||||
return 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using Key = K;
|
using Key = K;
|
||||||
|
@ -322,7 +293,8 @@ public:
|
||||||
octa::IsConvertible<RangeReference<R>, Value>::value,
|
octa::IsConvertible<RangeReference<R>, Value>::value,
|
||||||
bool
|
bool
|
||||||
> = true
|
> = true
|
||||||
): p_table(size ? size : estimate_rsize(range), hf, eqf, alloc) {
|
): p_table(size ? size : octa::detail::estimate_hrsize(range),
|
||||||
|
hf, eqf, alloc) {
|
||||||
for (; !range.empty(); range.pop_front())
|
for (; !range.empty(); range.pop_front())
|
||||||
emplace(range.front());
|
emplace(range.front());
|
||||||
p_table.rehash_up();
|
p_table.rehash_up();
|
||||||
|
@ -364,7 +336,7 @@ public:
|
||||||
Multimap &
|
Multimap &
|
||||||
> operator=(R range) {
|
> operator=(R range) {
|
||||||
clear();
|
clear();
|
||||||
p_table.reserve_at_least(estimate_rsize(range));
|
p_table.reserve_at_least(octa::detail::estimate_hrsize(range));
|
||||||
for (; !range.empty(); range.pop_front())
|
for (; !range.empty(); range.pop_front())
|
||||||
emplace(range.front());
|
emplace(range.front());
|
||||||
p_table.rehash_up();
|
p_table.rehash_up();
|
||||||
|
|
40
octa/set.h
40
octa/set.h
|
@ -42,21 +42,6 @@ private:
|
||||||
>;
|
>;
|
||||||
Base p_table;
|
Base p_table;
|
||||||
|
|
||||||
template<typename R>
|
|
||||||
octa::Size estimate_rsize(const R &range,
|
|
||||||
octa::EnableIf<octa::IsFiniteRandomAccessRange<R>::value, bool> = true
|
|
||||||
) {
|
|
||||||
return range.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename R>
|
|
||||||
octa::Size estimate_rsize(const R &,
|
|
||||||
octa::EnableIf<!octa::IsFiniteRandomAccessRange<R>::value, bool> = true
|
|
||||||
) {
|
|
||||||
/* we have no idea how big the range actually is */
|
|
||||||
return 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using Key = T;
|
using Key = T;
|
||||||
|
@ -100,7 +85,8 @@ public:
|
||||||
octa::IsConvertible<RangeReference<R>, Value>::value,
|
octa::IsConvertible<RangeReference<R>, Value>::value,
|
||||||
bool
|
bool
|
||||||
> = true
|
> = true
|
||||||
): p_table(size ? size : estimate_rsize(range), hf, eqf, alloc) {
|
): p_table(size ? size : octa::detail::estimate_hrsize(range),
|
||||||
|
hf, eqf, alloc) {
|
||||||
for (; !range.empty(); range.pop_front())
|
for (; !range.empty(); range.pop_front())
|
||||||
emplace(range.front());
|
emplace(range.front());
|
||||||
p_table.rehash_up();
|
p_table.rehash_up();
|
||||||
|
@ -142,7 +128,7 @@ public:
|
||||||
Set &
|
Set &
|
||||||
> operator=(R range) {
|
> operator=(R range) {
|
||||||
clear();
|
clear();
|
||||||
p_table.reserve_at_least(estimate_rsize(range));
|
p_table.reserve_at_least(octa::detail::estimate_hrsize(range));
|
||||||
for (; !range.empty(); range.pop_front())
|
for (; !range.empty(); range.pop_front())
|
||||||
emplace(range.front());
|
emplace(range.front());
|
||||||
p_table.rehash_up();
|
p_table.rehash_up();
|
||||||
|
@ -227,21 +213,6 @@ private:
|
||||||
>;
|
>;
|
||||||
Base p_table;
|
Base p_table;
|
||||||
|
|
||||||
template<typename R>
|
|
||||||
octa::Size estimate_rsize(const R &range,
|
|
||||||
octa::EnableIf<octa::IsFiniteRandomAccessRange<R>::value, bool> = true
|
|
||||||
) {
|
|
||||||
return range.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename R>
|
|
||||||
octa::Size estimate_rsize(const R &,
|
|
||||||
octa::EnableIf<!octa::IsFiniteRandomAccessRange<R>::value, bool> = true
|
|
||||||
) {
|
|
||||||
/* we have no idea how big the range actually is */
|
|
||||||
return 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using Key = T;
|
using Key = T;
|
||||||
|
@ -288,7 +259,8 @@ public:
|
||||||
octa::IsConvertible<RangeReference<R>, Value>::value,
|
octa::IsConvertible<RangeReference<R>, Value>::value,
|
||||||
bool
|
bool
|
||||||
> = true
|
> = true
|
||||||
): p_table(size ? size : estimate_rsize(range), hf, eqf, alloc) {
|
): p_table(size ? size : octa::detail::estimate_hrsize(range),
|
||||||
|
hf, eqf, alloc) {
|
||||||
for (; !range.empty(); range.pop_front())
|
for (; !range.empty(); range.pop_front())
|
||||||
emplace(range.front());
|
emplace(range.front());
|
||||||
p_table.rehash_up();
|
p_table.rehash_up();
|
||||||
|
@ -330,7 +302,7 @@ public:
|
||||||
Multiset &
|
Multiset &
|
||||||
> operator=(R range) {
|
> operator=(R range) {
|
||||||
clear();
|
clear();
|
||||||
p_table.reserve_at_least(estimate_rsize(range));
|
p_table.reserve_at_least(octa::detail::estimate_hrsize(range));
|
||||||
for (; !range.empty(); range.pop_front())
|
for (; !range.empty(); range.pop_front())
|
||||||
emplace(range.front());
|
emplace(range.front());
|
||||||
p_table.rehash_up();
|
p_table.rehash_up();
|
||||||
|
|
Loading…
Reference in New Issue