SDSL  3.0.0
Succinct Data Structure Library
lcp_bitcompressed.hpp
Go to the documentation of this file.
1 // Copyright (c) 2016, the SDSL Project Authors. All rights reserved.
2 // Please see the AUTHORS file for details. Use of this source code is governed
3 // by a BSD license that can be found in the LICENSE file.
8 #ifndef INCLUDED_SDSL_LCP_BITCOMPRESSED
9 #define INCLUDED_SDSL_LCP_BITCOMPRESSED
10 
11 #include <sdsl/int_vector.hpp>
12 #include <sdsl/iterators.hpp>
13 #include <sdsl/lcp.hpp>
14 
15 namespace sdsl
16 {
17 
18 template <uint8_t t_width = 0>
20 {
21  public:
26  typedef const value_type const_reference;
29  typedef const pointer const_pointer;
30  typedef ptrdiff_t difference_type;
31 
34 
35  enum
36  {
39  sa_order = 1
40  };
41 
42  template <class Cst>
44 
45  private:
46  int_vector<t_width> m_lcp;
47 
48  public:
55 
58  {
59  std::string lcp_file = cache_file_name(conf::KEY_LCP, config);
60  int_vector_buffer<> lcp_buf(lcp_file);
61  m_lcp = int_vector<t_width>(lcp_buf.size(), 0, lcp_buf.width());
62  for (size_type i = 0; i < m_lcp.size(); ++i) { m_lcp[i] = lcp_buf[i]; }
63  }
64 
66  size_type size() const { return m_lcp.size(); }
67 
70 
72  bool empty() const { return m_lcp.empty(); }
73 
75  const_iterator begin() const { return const_iterator(this, 0); }
76 
78  const_iterator end() const { return const_iterator(this, size()); }
79 
81 
83  value_type operator[](size_type i) const { return m_lcp[i]; }
84 
85  template <typename archive_t>
86  void CEREAL_SAVE_FUNCTION_NAME(archive_t & ar) const
87  {
88  ar(CEREAL_NVP(m_lcp));
89  }
90 
91  template <typename archive_t>
92  void CEREAL_LOAD_FUNCTION_NAME(archive_t & ar)
93  {
94  ar(CEREAL_NVP(m_lcp));
95  }
96 
98  size_type serialize(std::ostream & out, structure_tree_node * v = nullptr, std::string name = "") const
99  {
100  structure_tree_node * child = structure_tree::add_child(v, name, util::class_name(*this));
101  size_type written_bytes = 0;
102  written_bytes += m_lcp.serialize(out, child, "lcp");
103  structure_tree::add_size(child, written_bytes);
104  return written_bytes;
105  }
106 
108  bool operator==(lcp_bitcompressed const & other) const noexcept { return (m_lcp == other.m_lcp); }
109 
111  bool operator!=(lcp_bitcompressed const & other) const noexcept { return !(*this == other); }
112 
114  void load(std::istream & in) { m_lcp.load(in); }
115 };
116 
117 } // end namespace sdsl
118 #endif
#define CEREAL_NVP(X)
Definition: cereal.hpp:30
uint64_t size() const
Returns the number of elements currently stored.
uint8_t width() const
Returns the width of the integers which are accessed via the [] operator.
A generic vector class for integers of width .
Definition: int_vector.hpp:253
bool empty() const noexcept
Equivalent to size() == 0.
Definition: int_vector.hpp:524
int_vector_size_type size_type
Definition: int_vector.hpp:266
void load(std::istream &in)
Load the int_vector for a stream.
size_type size() const noexcept
The number of elements in the int_vector.
int_vector_trait< t_width >::value_type value_type
Definition: int_vector.hpp:255
size_type serialize(std::ostream &out, structure_tree_node *v=nullptr, std::string name="") const
Serializes the int_vector to a stream.
static size_type max_size() noexcept
Maximum size of the int_vector.
Definition: int_vector.hpp:566
const_iterator begin() const
Returns a const_iterator to the first element.
size_type size() const
Number of elements in the instance.
lcp_bitcompressed(const lcp_bitcompressed &)=default
bool empty() const
Returns if the data structure is empty.
lcp_bitcompressed()
Default Constructor.
lcp_bitcompressed & operator=(const lcp_bitcompressed &)=default
static size_type max_size()
Returns the largest size that lcp_bitcompressed can ever have.
lcp_bitcompressed & operator=(lcp_bitcompressed &&)=default
random_access_const_iterator< lcp_bitcompressed > const_iterator
value_type operator[](size_type i) const
Access operator.
const_iterator end() const
Returns a const_iterator to the element after the last element.
int_vector< t_width >::size_type size_type
lcp_bitcompressed(lcp_bitcompressed &&)=default
bool operator!=(lcp_bitcompressed const &other) const noexcept
Inequality operator.
int_vector< t_width >::value_type value_type
void load(std::istream &in)
Load from a stream.
bool operator==(lcp_bitcompressed const &other) const noexcept
Equality operator.
const value_type const_reference
size_type serialize(std::ostream &out, structure_tree_node *v=nullptr, std::string name="") const
Serialize to a stream.
void CEREAL_SAVE_FUNCTION_NAME(archive_t &ar) const
void CEREAL_LOAD_FUNCTION_NAME(archive_t &ar)
lcp_bitcompressed(cache_config &config)
Constructor taking a cache_config.
Generic iterator for a random access container.
Definition: iterators.hpp:24
static void add_size(structure_tree_node *v, uint64_t value)
static structure_tree_node * add_child(structure_tree_node *v, const std::string &name, const std::string &type)
int_vector.hpp contains the sdsl::int_vector class.
iterators.hpp contains an generic iterator for random access containers.
lcp.hpp contains classes for lcp information.
constexpr char KEY_LCP[]
Definition: config.hpp:44
Namespace for the succinct data structure library.
std::string cache_file_name(const std::string &key, const cache_config &config)
Returns the file name of the resource.
Definition: io.hpp:630
Helper class for construction process.
Definition: config.hpp:67