ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
BalancedParentheses.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*----------------------- File BalancedParentheses.h -----------------------*/
3/*--------------------------------------------------------------------------*/
88/*--------------------------------------------------------------------------*/
89/*----------------------------- DEFINITIONS --------------------------------*/
90/*--------------------------------------------------------------------------*/
91
92#ifndef __ADS_BalancedParentheses
93 #define __ADS_BalancedParentheses
94/* self-identification: #endif constant */
95
96/*--------------------------------------------------------------------------*/
97/*------------------------------ INCLUDES ----------------------------------*/
98/*--------------------------------------------------------------------------*/
99
100#include "ADS/Contract.h"
103
104#include <algorithm>
105#include <array>
106#include <cstddef>
107#include <cstdint>
108#include <string_view>
109#include <vector>
110
111/*--------------------------------------------------------------------------*/
112/*--------------------------- NAMESPACE ------------------------------------*/
113/*--------------------------------------------------------------------------*/
114
115namespace ADS
116{
117
118/*--------------------------------------------------------------------------*/
119/*----------------------- CLASS BalancedParentheses ------------------------*/
120/*--------------------------------------------------------------------------*/
121
124{
125
126/*--------------------------------------------------------------------------*/
127 public:
128 static constexpr std::size_t nil = std::size_t( -1 );
129
132
164
166 [[nodiscard]] std::size_t size( void ) const;
167
170 [[nodiscard]] bool operator[]( std::size_t i ) const;
171
175 [[nodiscard]] std::int64_t excess( std::size_t i ) const;
176
218 [[nodiscard]] std::size_t findClose( std::size_t i ) const;
219
235 [[nodiscard]] std::size_t forwardSearch( std::size_t i ,
236 std::int64_t d ) const;
237
254 [[nodiscard]] std::size_t findOpen( std::size_t j ) const;
255
271 [[nodiscard]] std::size_t enclose( std::size_t i ) const;
272
274 [[nodiscard]] const CompactRankSelect & bits( void ) const;
275
277 [[nodiscard]] std::size_t treeBits( void ) const;
278
279/*----------------------------- THE PERSISTENCE ----------------------------*/
280
282 static constexpr std::string_view persistName = "BalancedParentheses";
283
286 template< class A >
287 void persist( A & a );
288
289/*--------------------------------------------------------------------------*/
290 private:
291 static constexpr std::size_t kLeaf = 512;
292 static constexpr std::size_t kGroup = 16;
293
297 [[nodiscard]] std::size_t scanForward( std::size_t a , std::size_t b ,
298 std::int64_t & e ,
299 std::int64_t d ) const;
300
304 [[nodiscard]] std::size_t scanBackward( std::size_t a , std::size_t b ,
305 std::int64_t & e ,
306 std::int64_t d ) const;
307
310 [[nodiscard]] std::size_t backwardSearch( std::size_t i ,
311 std::int64_t d ) const;
312
314 [[nodiscard]] std::size_t leafEnd( std::size_t l ) const {
315 return( std::min( size() , ( l + 1 ) * kLeaf ) );
316 }
317
319 [[nodiscard]] bool balanced( void ) const;
320
322 std::size_t f_nleaf = 0;
323 std::size_t f_groups = 1;
326 std::vector< std::int16_t > f_lexc , f_lmin;
328 std::vector< std::int64_t > f_exc , f_min;
329
330 }; // end( class BalancedParentheses )
331
332/*--------------------------------------------------------------------------*/
333
334} // end( namespace ADS )
335
336/*--------------------------------------------------------------------------*/
337/*-------------------------- IMPLEMENTATION --------------------------------*/
338/*--------------------------------------------------------------------------*/
339
340#include "ADS/succinct/impl/BalancedParentheses.tpp"
341
342/*--------------------------------------------------------------------------*/
343
344#endif /* BalancedParentheses.h included */
345
346/*--------------------------------------------------------------------------*/
347/*--------------------- End File BalancedParentheses.h ---------------------*/
348/*--------------------------------------------------------------------------*/
The vector of bits on which the succinct structures and the integer codes of ADS are built: the bits ...
Rank and select on a static vector of bits of bits in 3.125% of bits more for the rank and less th...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
BalancedParentheses(void)
the empty sequence
std::size_t treeBits(void) const
the bits of the range min-max tree
BalancedParentheses(BitVector b)
the parentheses , 1 for an open one and 0 for a closed one, and the range min-max tree on them
std::int64_t excess(std::size_t i) const
, the open parentheses minus the closed ones in , as
bool operator[](std::size_t i) const
whether the place has an open parenthesis
std::size_t findClose(std::size_t i) const
the closed parenthesis of the open one at
std::size_t forwardSearch(std::size_t i, std::int64_t d) const
the first with , nil if none: the end of a run of parentheses that goes levels below the one at ,...
std::size_t enclose(std::size_t i) const
the open parenthesis of the pair that encloses the open one at , nil if none
std::size_t size(void) const
the number of parentheses
static constexpr std::size_t nil
no place
Definition BalancedParentheses.h:128
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
const CompactRankSelect & bits(void) const
the parentheses with their rank and select
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition BalancedParentheses.h:282
std::size_t findOpen(std::size_t j) const
the open parenthesis of the closed one at
a vector of bits packed in words of 64 bits
Definition BitVector.h:479
a static vector of bits with rank and select in 3.125% of its bits more for the rank and less than 0....
Definition CompactRankSelect.h:118
Definition ADT.h:96