souffle  2.0.2-371-g6315b36
Public Types | Public Member Functions | Private Types | Private Attributes | Friends
souffle::Trie< Dim > Class Template Reference

#include <Brie.h>

Collaboration diagram for souffle::Trie< Dim >:
Collaboration graph

Public Types

using const_entry_span_type = typename types::const_entry_span_type
 
using element_type = entry_type
 
using entry_span_type = typename types::entry_span_type
 
using entry_type = typename types::entry_type
 
using iterator = typename types::iterator
 
using iterator_core = typename types::iterator_core
 
using op_context = typename types::op_context
 
using operation_hints = op_context
 

Public Member Functions

iterator begin () const
 Obtains an iterator referencing the first element stored within this trie. More...
 
void clear ()
 Removes all entries within this trie. More...
 
bool contains (const_entry_span_type tuple, op_context &ctxt) const
 
bool empty () const
 Determines whether this trie is empty or not. More...
 
iterator end () const
 Obtains an iterator referencing the position after the last element stored within this trie. More...
 
iterator find (const_entry_span_type entry, op_context &ctxt) const
 
template<unsigned levels>
range< iteratorgetBoundaries (const entry_type &entry) const
 
template<unsigned levels>
range< iteratorgetBoundaries (const entry_type &entry, op_context &ctxt) const
 
template<unsigned levels>
range< iteratorgetBoundaries (const_entry_span_type entry) const
 
template<unsigned levels>
range< iteratorgetBoundaries (const_entry_span_type entry, op_context &ctxt) const
 Obtains a range of elements matching the prefix of the given entry up to levels elements. More...
 
template<unsigned levels, typename... Values, typename = std::enable_if_t<(isRamType<Values> && ...)>>
range< iteratorgetBoundaries (Values... values) const
 
std::size_t getMemoryUsage () const
 Computes the total memory usage of this data structure. More...
 
bool insert (const_entry_span_type tuple, op_context &ctxt)
 Inserts a new entry. More...
 
iterator lower_bound (const_entry_span_type entry, op_context &) const
 Obtains an iterator to the first element not less than the given entry value. More...
 
std::vector< range< iterator > > partition (unsigned chunks=500) const
 Computes a partition of an approximate number of chunks of the content of this trie. More...
 
std::size_t size () const
 Determines the number of entries in this trie. More...
 
iterator upper_bound (const_entry_span_type entry, op_context &) const
 Obtains an iterator to the first element greater than the given entry value, or end if there is no such element. More...
 
 ~Trie ()
 

Private Types

using base = TrieBase< Dim, Trie< Dim > >
 
using nested_trie_type = typename types::nested_trie_type
 
using store_type = typename types::store_type
 
using types = TrieTypes< Dim >
 

Private Attributes

store_type store
 

Friends

template<unsigned N>
class Trie
 

Detailed Description

template<unsigned Dim>
class souffle::Trie< Dim >

Definition at line 79 of file Brie.h.

Member Typedef Documentation

◆ base

template<unsigned Dim>
using souffle::Trie< Dim >::base = TrieBase<Dim, Trie<Dim> >
private

Definition at line 2659 of file Brie.h.

◆ const_entry_span_type

template<unsigned Dim>
using souffle::Trie< Dim >::const_entry_span_type = typename types::const_entry_span_type

Definition at line 2667 of file Brie.h.

◆ element_type

template<unsigned Dim>
using souffle::Trie< Dim >::element_type = entry_type

Definition at line 2675 of file Brie.h.

◆ entry_span_type

template<unsigned Dim>
using souffle::Trie< Dim >::entry_span_type = typename types::entry_span_type

Definition at line 2668 of file Brie.h.

◆ entry_type

template<unsigned Dim>
using souffle::Trie< Dim >::entry_type = typename types::entry_type

Definition at line 2669 of file Brie.h.

◆ iterator

template<unsigned Dim>
using souffle::Trie< Dim >::iterator = typename types::iterator

Definition at line 2670 of file Brie.h.

◆ iterator_core

template<unsigned Dim>
using souffle::Trie< Dim >::iterator_core = typename types::iterator_core

Definition at line 2671 of file Brie.h.

◆ nested_trie_type

template<unsigned Dim>
using souffle::Trie< Dim >::nested_trie_type = typename types::nested_trie_type
private

Definition at line 2661 of file Brie.h.

◆ op_context

template<unsigned Dim>
using souffle::Trie< Dim >::op_context = typename types::op_context

Definition at line 2672 of file Brie.h.

◆ operation_hints

template<unsigned Dim>
using souffle::Trie< Dim >::operation_hints = op_context

Definition at line 2674 of file Brie.h.

◆ store_type

template<unsigned Dim>
using souffle::Trie< Dim >::store_type = typename types::store_type
private

Definition at line 2662 of file Brie.h.

◆ types

template<unsigned Dim>
using souffle::Trie< Dim >::types = TrieTypes<Dim>
private

Definition at line 2660 of file Brie.h.

Constructor & Destructor Documentation

◆ ~Trie()

template<unsigned Dim>
souffle::Trie< Dim >::~Trie ( )
inline

Definition at line 2687 of file Brie.h.

Member Function Documentation

◆ begin()

template<unsigned Dim>
iterator souffle::detail::brie::TrieBase< Dim, Derived >::begin
inline

Obtains an iterator referencing the first element stored within this trie.

Definition at line 2082 of file Brie.h.

2094  {

Referenced by souffle::TEST().

◆ clear()

template<unsigned Dim>
void souffle::Trie< Dim >::clear ( )
inline

Removes all entries within this trie.

Definition at line 2718 of file Brie.h.

2720  {
2721  using value_t = typename store_type::value_type;
2722  using atomic_value_t = typename store_type::atomic_value_type;
2723 
2724  // check context
2725  if (ctxt.lastNested && ctxt.lastQuery == tuple[0]) {

References souffle::detail::brie::tail().

Here is the call graph for this function:

◆ contains()

template<unsigned Dim>
bool souffle::Trie< Dim >::contains ( const_entry_span_type  tuple,
op_context ctxt 
) const
inline

Definition at line 2778 of file Brie.h.

2778  {};
2779  }
2780 
2781  // conduct recursive step
2782  return next && next->contains(tail(tuple), ctxt.nestedCtxt);
2783  }
2784 
2785  /**
2786  * Obtains a range of elements matching the prefix of the given entry up to
2787  * levels elements. A operation context may be provided to exploit temporal
2788  * locality.
2789  *
2790  * @tparam levels the length of the requested matching prefix
2791  * @param entry the entry to be looking for
2792  * @param ctxt the operation context to be utilized
2793  * @return the corresponding range of matching elements
2794  */
2795  template <unsigned levels>
2796  range<iterator> getBoundaries(const_entry_span_type entry, op_context& ctxt) const {
2797  // if nothing is bound => just use begin and end
2798  if constexpr (levels == 0) return make_range(begin(), end());
2799 

Referenced by souffle::TEST().

◆ empty()

template<unsigned Dim>
bool souffle::detail::brie::TrieBase< Dim, Derived >::empty
inline

Determines whether this trie is empty or not.

Definition at line 2075 of file Brie.h.

2078  {

◆ end()

template<unsigned Dim>
iterator souffle::detail::brie::TrieBase< Dim, Derived >::end
inline

Obtains an iterator referencing the position after the last element stored within this trie.

Definition at line 2090 of file Brie.h.

2094  {

Referenced by souffle::TEST().

◆ find()

template<unsigned Dim>
iterator souffle::detail::brie::TrieBase< Dim, Derived >::find
inline

Definition at line 2094 of file Brie.h.

2094  {
2095  op_context ctxt;
2096  return impl().template getBoundaries<levels>(entry, ctxt);
2097  }

◆ getBoundaries() [1/5]

template<unsigned Dim>
template<unsigned levels>
range<iterator> souffle::detail::brie::TrieBase< Dim, Derived >::getBoundaries ( unsigned  levels)
inline

Definition at line 2121 of file Brie.h.

2123  { \

◆ getBoundaries() [2/5]

template<unsigned Dim>
template<unsigned levels>
range<iterator> souffle::detail::brie::TrieBase< Dim, Derived >::getBoundaries ( unsigned  levels)
inline

Definition at line 2116 of file Brie.h.

2116  { \
2117  op_context ctxt; \
2118  return impl().fn(entry, ctxt); \

◆ getBoundaries() [3/5]

template<unsigned Dim>
template<unsigned levels>
range<iterator> souffle::detail::brie::TrieBase< Dim, Derived >::getBoundaries ( unsigned  levels)
inline

Definition at line 2110 of file Brie.h.

2110  {
2111  return impl().template getBoundaries<levels>(entry_type{ramBitCast(values)...});
2112  }
2113 

◆ getBoundaries() [4/5]

template<unsigned Dim>
template<unsigned levels>
range<iterator> souffle::Trie< Dim >::getBoundaries ( const_entry_span_type  entry,
op_context ctxt 
) const
inline

Obtains a range of elements matching the prefix of the given entry up to levels elements.

A operation context may be provided to exploit temporal locality.

Template Parameters
levelsthe length of the requested matching prefix
Parameters
entrythe entry to be looking for
ctxtthe operation context to be utilized
Returns
the corresponding range of matching elements

Definition at line 2812 of file Brie.h.

2818  {};
2819  iterator end{};
2820 
2821  // adapt them level by level
2822  auto found = fix_binding<levels, 0, Dim>()(store, begin, end, entry);
2823  if (!found) return make_range(iterator(), iterator());
2824 
2825  // update context
2826  static_assert(std::tuple_size_v<decltype(ctxt.lastBoundaryRequest)> == Dim);
2827  static_assert(std::tuple_size_v<decltype(entry)> == Dim);
2828  ctxt.lastBoundaryLevels = levels;
2829  std::copy_n(entry.begin(), Dim, ctxt.lastBoundaryRequest.begin());
2830  ctxt.lastBoundaries = make_range(begin, end);
2831 
2832  // use the result
2833  return ctxt.lastBoundaries;
2834  }
2835 
2836  /**
2837  * Obtains an iterator to the first element not less than the given entry value.
2838  *
2839  * @param entry the lower bound for this search
2840  * @param ctxt the operation context to be utilized
2841  * @return an iterator addressing the first element in this structure not less than the given value
2842  */
2843  iterator lower_bound(const_entry_span_type entry, op_context& /* ctxt */) const {
2844  // start with a default-initialized iterator
2845  iterator res;
2846 
2847  // adapt it level by level
2848  bool found = fix_lower_bound<Dim>()(store, res, entry);
2849 
2850  // use the result

◆ getBoundaries() [5/5]

template<unsigned Dim>
template<unsigned levels, typename... Values, typename = std::enable_if_t<(isRamType<Values> && ...)>>
range<iterator> souffle::detail::brie::TrieBase< Dim, Derived >::getBoundaries ( unsigned  levels,
typename...  Values,
typename  = std::enable_if_t<(isRamType<Values> && ...)> 
)
inline

Definition at line 2126 of file Brie.h.

2138  {

◆ getMemoryUsage()

template<unsigned Dim>
std::size_t souffle::Trie< Dim >::getMemoryUsage ( ) const
inline

Computes the total memory usage of this data structure.

Definition at line 2706 of file Brie.h.

2720  {

◆ insert()

template<unsigned Dim>
bool souffle::Trie< Dim >::insert ( const_entry_span_type  tuple,
op_context ctxt 
)
inline

Inserts a new entry.

A operation context may be provided to exploit temporal locality.

Parameters
tuplethe entry to be added
ctxtthe operation context to be utilized
Returns
true if the same tuple hasn't been present before, false otherwise

Definition at line 2736 of file Brie.h.

2739  {
2740  // create a sub-tree && register it atomically
2741  auto newNested = std::make_unique<nested_trie_type>();
2742  if (next.compare_exchange_weak(nextPtr, newNested.get())) {
2743  nextPtr = newNested.release(); // worked, ownership is acquired by `store`
2744  }
2745  // otherwise some other thread was faster => use its version
2746  }
2747 
2748  // make sure a next has been established
2749  assert(nextPtr);
2750 
2751  // clear context if necessary
2752  if (nextPtr != ctxt.lastNested) {
2753  ctxt.lastQuery = tuple[0];
2754  ctxt.lastNested = nextPtr;
2755  ctxt.nestedCtxt = {};
2756  }
2757 
2758  // conduct recursive step
2759  return nextPtr->insert(tail(tuple), ctxt.nestedCtxt);
2760  }
2761 
2762  bool contains(const_entry_span_type tuple, op_context& ctxt) const {
2763  // check context
2764  if (ctxt.lastNested && ctxt.lastQuery == tuple[0]) {
2766  return ctxt.lastNested->contains(tail(tuple), ctxt.nestedCtxt);
2767  }
2768 
2770 
2771  // lookup next step
2772  auto next = store.lookup(tuple[0], ctxt.local);
2773 
2774  // clear context if necessary
2775  if (next != ctxt.lastNested) {
2776  ctxt.lastQuery = tuple[0];

◆ lower_bound()

template<unsigned Dim>
iterator souffle::Trie< Dim >::lower_bound ( const_entry_span_type  entry,
op_context  
) const
inline

Obtains an iterator to the first element not less than the given entry value.

Parameters
entrythe lower bound for this search
ctxtthe operation context to be utilized
Returns
an iterator addressing the first element in this structure not less than the given value

Definition at line 2859 of file Brie.h.

2862  {
2863  // start with a default-initialized iterator
2864  iterator res;
2865 
2866  // adapt it level by level
2867  bool found = fix_upper_bound<Dim>()(store, res, entry);
2868 

◆ partition()

template<unsigned Dim>
std::vector<range<iterator> > souffle::Trie< Dim >::partition ( unsigned  chunks = 500) const
inline

Computes a partition of an approximate number of chunks of the content of this trie.

Thus, the union of the resulting set of disjoint ranges is equivalent to the content of this trie.

Parameters
chunksthe number of chunks requested
Returns
a list of sub-ranges forming a partition of the content of this trie

Definition at line 2897 of file Brie.h.

2913  : public TrieBase<1u, Trie<1u>> {
2914  using base = TrieBase<1u, Trie<1u>>;
2915  using types = TrieTypes<1u>;
2916  using store_type = typename types::store_type;
2917 
2918  using base::store;
2919 

◆ size()

template<unsigned Dim>
std::size_t souffle::Trie< Dim >::size ( ) const
inline

Determines the number of entries in this trie.

Definition at line 2694 of file Brie.h.

2702  {

◆ upper_bound()

template<unsigned Dim>
iterator souffle::Trie< Dim >::upper_bound ( const_entry_span_type  entry,
op_context  
) const
inline

Obtains an iterator to the first element greater than the given entry value, or end if there is no such element.

Parameters
entrythe upper bound for this search
ctxtthe operation context to be utilized
Returns
an iterator addressing the first element in this structure greater than the given value

Definition at line 2878 of file Brie.h.

2881  {
2882  std::vector<range<iterator>> res;
2883 
2884  // shortcut for empty trie
2885  if (this->empty()) return res;
2886 
2887  // use top-level elements for partitioning

Friends And Related Function Documentation

◆ Trie

template<unsigned Dim>
template<unsigned N>
friend class Trie
friend

Definition at line 2656 of file Brie.h.

Field Documentation

◆ store

template<unsigned Dim>
store_type souffle::detail::brie::TrieBase< Dim, Derived >::store
private

Definition at line 2044 of file Brie.h.


The documentation for this class was generated from the following file:
souffle::Trie::base
TrieBase< Dim, Trie< Dim > > base
Definition: Brie.h:2659
souffle::CacheAccessCounter::addMiss
void addMiss()
Definition: CacheUtil.h:283
souffle::Trie::contains
bool contains(const_entry_span_type tuple, op_context &ctxt) const
Definition: Brie.h:2778
souffle::Trie::begin
iterator begin() const
Obtains an iterator referencing the first element stored within this trie.
Definition: Brie.h:2082
souffle::Trie::lower_bound
iterator lower_bound(const_entry_span_type entry, op_context &) const
Obtains an iterator to the first element not less than the given entry value.
Definition: Brie.h:2859
souffle::Trie::types
TrieTypes< Dim > types
Definition: Brie.h:2660
souffle::Trie::op_context
typename types::op_context op_context
Definition: Brie.h:2672
souffle::detail::brie::TrieTypes::store_type
SparseArray< nested_trie_type *, 6, nested_trie_merger, nested_trie_cloner > store_type
Definition: Brie.h:2489
souffle::Trie::const_entry_span_type
typename types::const_entry_span_type const_entry_span_type
Definition: Brie.h:2667
souffle::Trie::iterator
typename types::iterator iterator
Definition: Brie.h:2670
souffle::detail::brie::TrieBase::store
store_type store
Definition: Brie.h:2044
souffle::detail::brie::tail
auto tail(C &s)
Definition: Brie.h:110
souffle::Trie::store_type
typename types::store_type store_type
Definition: Brie.h:2662
souffle::make_range
range< Iter > make_range(const Iter &a, const Iter &b)
A utility function enabling the construction of ranges without explicitly specifying the iterator typ...
Definition: ContainerUtil.h:389
souffle::detail::brie::TrieBase::hint_statistics::inserts
CacheAccessCounter inserts
Definition: Brie.h:2156
souffle::CacheAccessCounter::addHit
void addHit()
Definition: CacheUtil.h:282
souffle::detail::brie::TrieBase::hint_stats
hint_statistics hint_stats
Definition: Brie.h:2167
souffle::Trie::end
iterator end() const
Obtains an iterator referencing the position after the last element stored within this trie.
Definition: Brie.h:2090
souffle::Trie::empty
bool empty() const
Determines whether this trie is empty or not.
Definition: Brie.h:2075
souffle::Trie::getBoundaries
range< iterator > getBoundaries(const_entry_span_type entry, op_context &ctxt) const
Obtains a range of elements matching the prefix of the given entry up to levels elements.
Definition: Brie.h:2812
souffle::Trie::store
store_type store
Definition: Brie.h:2044
souffle::ramBitCast
To ramBitCast(From source)
In C++20 there will be a new way to cast between types by reinterpreting bits (std::bit_cast),...
Definition: RamTypes.h:87
souffle::Trie::entry_type
typename types::entry_type entry_type
Definition: Brie.h:2669
souffle::detail::brie::TrieBase::hint_statistics::contains
CacheAccessCounter contains
Definition: Brie.h:2159