Ginger 1.1.5; VERSION ${PROJECT_VERSION}
Loading...
Searching...
No Matches
robin.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <vector>
9
10namespace fun {
11
12 namespace detail {
18 template <typename T> struct RobinSlNode {
20 T key;
21 };
22
28 template <typename T> struct RobinIterator {
30 auto operator!=(const RobinIterator& other) const -> bool { return cur != other.cur; }
31 auto operator==(const RobinIterator& other) const -> bool { return cur == other.cur; }
33 cur = cur->next;
34 return *this;
35 }
36 auto operator*() const -> const T& { return cur->key; }
37 };
38
44 template <typename T> struct RobinIterableWrapper {
46 // const Robin<T> *rr;
47 // T from_part;
48 auto begin() const -> RobinIterator<T> { return RobinIterator<T>{node->next}; }
49 auto end() const -> RobinIterator<T> { return RobinIterator<T>{node}; }
50 // auto size() const -> size_t { return rr->cycle.size() - 1; }
51 };
52 } // namespace detail
53
62 template <typename T> struct Robin {
63 std::vector<detail::RobinSlNode<T>> cycle;
64
72 explicit Robin(T num_parts) : cycle(num_parts) {
73 auto* slptr = &this->cycle[num_parts - 1];
74 auto k = T(0);
75 for (auto& sl : this->cycle) {
76 sl.key = k;
77 slptr->next = &sl;
78 slptr = slptr->next;
79 ++k;
80 }
81 }
82
92 auto exclude(T from_part) const -> detail::RobinIterableWrapper<T> {
93 return detail::RobinIterableWrapper<T>{&this->cycle[from_part]};
94 }
95 };
96
97} // namespace fun
Definition robin.hpp:10
Robin Hood iterator for cycle iteration.
Definition robin.hpp:62
Robin(T num_parts)
Construct a new Robin cycle.
Definition robin.hpp:72
auto exclude(T from_part) const -> detail::RobinIterableWrapper< T >
Get an iterable that excludes a specific element.
Definition robin.hpp:92
std::vector< detail::RobinSlNode< T > > cycle
Definition robin.hpp:63
Wrapper to make the linked list iterable.
Definition robin.hpp:44
auto end() const -> RobinIterator< T >
Definition robin.hpp:49
auto begin() const -> RobinIterator< T >
Definition robin.hpp:48
const detail::RobinSlNode< T > * node
Definition robin.hpp:45
Iterator for the Robin Hood linked list.
Definition robin.hpp:28
auto operator!=(const RobinIterator &other) const -> bool
Definition robin.hpp:30
auto operator++() -> RobinIterator &
Definition robin.hpp:32
auto operator*() const -> const T &
Definition robin.hpp:36
const RobinSlNode< T > * cur
Definition robin.hpp:29
auto operator==(const RobinIterator &other) const -> bool
Definition robin.hpp:31
A node in the Robin Hood hashing linked list.
Definition robin.hpp:18
T key
Definition robin.hpp:20
RobinSlNode * next
Definition robin.hpp:19