ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
K2Tree.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*----------------------------- File K2Tree.h ------------------------------*/
3/*--------------------------------------------------------------------------*/
54/*--------------------------------------------------------------------------*/
55/*----------------------------- DEFINITIONS --------------------------------*/
56/*--------------------------------------------------------------------------*/
57
58#ifndef __ADS_K2Tree
59 #define __ADS_K2Tree
60/* self-identification: #endif constant */
61
62/*--------------------------------------------------------------------------*/
63/*------------------------------ INCLUDES ----------------------------------*/
64/*--------------------------------------------------------------------------*/
65
66#include "ADS/Contract.h"
69
70#include <algorithm>
71#include <cstddef>
72#include <cstdint>
73#include <string_view>
74#include <utility>
75#include <vector>
76
77/*--------------------------------------------------------------------------*/
78/*--------------------------- NAMESPACE ------------------------------------*/
79/*--------------------------------------------------------------------------*/
80
81namespace ADS
82{
83
84/*--------------------------------------------------------------------------*/
85/*------------------------------ CLASS K2Tree ------------------------------*/
86/*--------------------------------------------------------------------------*/
87
89class K2Tree
90{
91
92/*--------------------------------------------------------------------------*/
93 public:
95 using Edge = std::pair< std::size_t , std::size_t >;
96
98 K2Tree( void ) = default;
99
134 K2Tree( std::size_t n , const std::vector< Edge > & e , std::size_t k = 2 );
135
137 [[nodiscard]] std::size_t order( void ) const;
138
140 [[nodiscard]] std::size_t edges( void ) const;
141
167 [[nodiscard]] std::vector< std::size_t > neighbors( std::size_t u ) const;
168
173 [[nodiscard]] std::vector< std::size_t >
174 reverseNeighbors( std::size_t v ) const;
175
195 [[nodiscard]] bool hasEdge( std::size_t u , std::size_t v ) const;
196
198 [[nodiscard]] const BitVector & levels( void ) const;
199
201 [[nodiscard]] const BitVector & leaves( void ) const;
202
204 [[nodiscard]] std::size_t sizeInBits( void ) const;
205
206/*----------------------------- THE PERSISTENCE ----------------------------*/
207
209 static constexpr std::string_view persistName = "K2Tree";
210
213 template< class A >
214 void persist( A & a );
215
216/*--------------------------------------------------------------------------*/
217 private:
219 [[nodiscard]] bool mark( std::size_t p ) const;
220
223 [[nodiscard]] std::size_t children( std::size_t p ) const;
224
228 void walk( std::size_t s , std::size_t r , std::size_t o , std::size_t base ,
229 bool row , std::vector< std::size_t > & out ) const;
230
231 std::size_t f_n = 0;
232 std::size_t f_k = 2;
233 std::size_t f_side = 1;
234 std::size_t f_m = 0;
235 RankSelect f_t;
236 BitVector f_l;
237
238 }; // end( class K2Tree )
239
240/*--------------------------------------------------------------------------*/
241
242} // end( namespace ADS )
243
244/*--------------------------------------------------------------------------*/
245/*-------------------------- IMPLEMENTATION --------------------------------*/
246/*--------------------------------------------------------------------------*/
247
248#include "ADS/succinct/impl/K2Tree.tpp"
249
250/*--------------------------------------------------------------------------*/
251
252#endif /* K2Tree.h included */
253
254/*--------------------------------------------------------------------------*/
255/*---------------------------- End File K2Tree.h ---------------------------*/
256/*--------------------------------------------------------------------------*/
The vector of bits on which the succinct structures and the integer codes of ADS are built: the bits ...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
Rank and select on a static vector of bits of bits with 1s (chapter 15, Compressed Data Structures...
a vector of bits packed in words of 64 bits
Definition BitVector.h:479
K2Tree(std::size_t n, const std::vector< Edge > &e, std::size_t k=2)
the graph of nodes and the edges (repeated ones counted once)
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
std::size_t sizeInBits(void) const
the bits of , and the rank directory of
std::size_t edges(void) const
the number of distinct edges
const BitVector & leaves(void) const
, the marks of the cells
std::pair< std::size_t, std::size_t > Edge
an edge , from to
Definition K2Tree.h:95
std::size_t order(void) const
the number of nodes,
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition K2Tree.h:209
std::vector< std::size_t > reverseNeighbors(std::size_t v) const
the predecessors of , in increasing order: the walk of neighbors() on the children that cross the col...
std::vector< std::size_t > neighbors(std::size_t u) const
the successors of , in increasing order
const BitVector & levels(void) const
, the marks of the levels but the last
K2Tree(void)=default
the graph with no node
bool hasEdge(std::size_t u, std::size_t v) const
whether is an edge
BasicRankSelect< false > RankSelect
the directory with its inventories of select built in the constructor, the fastest select
Definition RankSelect.h:556
Definition ADT.h:96