20 #ifndef FST_EXTENSIONS_PDT_COLLECTION_H_ 21 #define FST_EXTENSIONS_PDT_COLLECTION_H_ 35 template <
class I,
class T>
42 Node() : node_id(kNoNodeId), element(T()) {}
44 Node(I i,
const T &t) : node_id(i), element(t) {}
53 static constexpr
auto kPrime = 7853;
63 : id_(id), node_(node), node_table_(node_table) {}
65 bool Done()
const {
return id_ == kNoNodeId; }
67 const T &
Element()
const {
return node_.element; }
71 if (id_ != kNoNodeId) node_ = node_table_->FindEntry(id_);
84 I
FindId(
const std::vector<T> &
set,
bool insert =
true) {
86 for (ssize_t i =
set.size() - 1; i >= 0; --i) {
87 Node node(node_id,
set[i]);
88 node_id = node_table_.FindId(node, insert);
89 if (node_id == -1)
break;
97 if (id < 0 || id >= node_table_.Size()) {
98 return SetIterator(kNoNodeId,
Node(kNoNodeId, T()), &node_table_);
100 return SetIterator(
id, node_table_.FindEntry(
id), &node_table_);
104 I
Size()
const {
return node_table_.Size(); }
107 static constexpr I kNoNodeId = -1;
108 static const std::hash<T> hash_;
113 template <
class I,
class T>
118 #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