20 #ifndef FST_EXTENSIONS_PDT_COLLECTION_H_ 21 #define FST_EXTENSIONS_PDT_COLLECTION_H_ 23 #include <sys/types.h> 38 template <
class I,
class T>
45 Node() : node_id(kNoNodeId), element(T()) {}
47 Node(I i,
const T &t) : node_id(i), element(t) {}
56 static constexpr
auto kPrime = 7853;
66 : id_(id), node_(node), node_table_(node_table) {}
68 bool Done()
const {
return id_ == kNoNodeId; }
70 const T &
Element()
const {
return node_.element; }
74 if (id_ != kNoNodeId) node_ = node_table_->FindEntry(id_);
87 I
FindId(
const std::vector<T> &
set,
bool insert =
true) {
89 for (ssize_t i =
set.size() - 1; i >= 0; --i) {
90 Node node(node_id,
set[i]);
91 node_id = node_table_.FindId(node, insert);
92 if (node_id == -1)
break;
100 if (id < 0 || id >= node_table_.Size()) {
101 return SetIterator(kNoNodeId,
Node(kNoNodeId, T()), &node_table_);
103 return SetIterator(
id, node_table_.FindEntry(
id), &node_table_);
107 I
Size()
const {
return node_table_.Size(); }
110 static constexpr I kNoNodeId = -1;
111 static const std::hash<T> hash_;
116 template <
class I,
class T>
121 #endif // FST_EXTENSIONS_PDT_COLLECTION_H_
I FindId(const std::vector< T > &set, bool insert=true)
size_t operator()(const Node &n) const
SetIterator(I id, Node node, NodeTable *node_table)
SetIterator FindSet(I id)
const T & Element() const
bool operator==(const Node &n) const