vdj_pipe
pipeline for processing DNA sequence data
vector_set.hpp
Go to the documentation of this file.
1 
7 #ifndef VECTOR_SET_HPP_
8 #define VECTOR_SET_HPP_
9 #include <vector>
10 #include <algorithm>
12 
13 namespace vdj_pipe{ namespace detail{
14 
17 template<class T, class Alloc = std::allocator<T> >
18 class Vector_set {
19  typedef std::vector<T, Alloc> stor_t;
20 public:
22  typedef T value_type;
23  typedef std::size_t size_type;
24  typedef std::ptrdiff_t difference_type;
25  typedef typename stor_t::iterator iterator;
26  typedef typename stor_t::const_iterator const_iterator;
27 
28  iterator begin() {return v_.begin();}
29  iterator end() {return v_.end();}
30  const_iterator begin() const {return v_.begin();}
31  const_iterator end() const {return v_.end();}
32  value_type const& front() const {return v_.front();}
33  value_type const& back() const {return v_.back();}
34  std::size_t size() const {return v_.size();}
35  bool empty() const {return v_.empty();}
36  void reserve(const std::size_t n) {v_.reserve(n);}
37  void pop_back() {v_.pop_back();}
38  void clear() {v_.clear();}
39 
40  template<class Iter> void insert(Iter i1, Iter i2) {
41  for( ; i1 != i2; ++i1 ) {
42  const iterator i = std::lower_bound(v_.begin(), v_.end(), *i1);
43  if( i == v_.end() || *i1 < *i ) {
44  v_.insert(i, *i1);
45  }
46  }
47  }
48 
49  std::pair<iterator, bool> insert(value_type const& t) {
50  iterator i = std::lower_bound(v_.begin(), v_.end(), t);
51  if( i == v_.end() || t < *i ) {
52  return std::make_pair(v_.insert(i, t), true);
53  }
54  return std::make_pair(i, false);
55  }
56 
57  template<typename CompatType>
58  unsigned erase(CompatType const& t) {
59  iterator i = std::lower_bound(v_.begin(), v_.end(), t);
60  if( i == v_.end() || t < *i ) return 0;
61  v_.erase(i);
62  return 1;
63  }
64 
68  template<typename CompatType>
69  value_type const* find(CompatType const& t) const {
70  const_iterator i = std::lower_bound(v_.begin(), v_.end(), t);
71  //i points to t == *i, to t < *i, or to i == end()
72  if( i == v_.end() || t < *i ) return 0;
73  return &(*i);
74  }
75 
76  value_type const& operator[](const std::size_t n) const {return v_[n];}
77  value_type& operator[](const std::size_t n) {return v_[n];}
78  value_type const& at(const std::size_t n) const {return v_.at(n);}
79  value_type& at(const std::size_t n) {return v_.at(n);}
80 
81  bool operator==(self_type const& vs2) const {return v_ == vs2.v_;}
82  bool operator<(self_type const& vs2) const {return v_ < vs2.v_;}
84 
85 private:
86  stor_t v_;
87 };
88 
89 }//namespace detail
90 }//namespace vdj_pipe
91 #endif /* VECTOR_SET_HPP_ */
const_iterator end() const
Definition: vector_set.hpp:31
#define VDJ_PIPE_COMPARISON_OPERATOR_MEMBERS(name)
Definition: comparison_operators_macro.hpp:10
std::size_t size() const
Definition: vector_set.hpp:34
stor_t::iterator iterator
Definition: vector_set.hpp:25
value_type const * find(CompatType const &t) const
Definition: vector_set.hpp:69
Collection of unique objects stored in an ordered vector.
Definition: vector_set.hpp:18
value_type const & at(const std::size_t n) const
Definition: vector_set.hpp:78
stor_t::const_iterator const_iterator
Definition: vector_set.hpp:26
void reserve(const std::size_t n)
Definition: vector_set.hpp:36
std::pair< iterator, bool > insert(value_type const &t)
Definition: vector_set.hpp:49
void clear()
Definition: vector_set.hpp:38
value_type const & front() const
Definition: vector_set.hpp:32
T value_type
Definition: vector_set.hpp:22
Main namespace of vdj_pipe library.
Definition: keywords_variable.hpp:11
void insert(Iter i1, Iter i2)
Definition: vector_set.hpp:40
stor_t v_
Definition: vector_set.hpp:86
bool operator==(self_type const &vs2) const
Definition: vector_set.hpp:81
value_type & operator[](const std::size_t n)
Definition: vector_set.hpp:77
iterator end()
Definition: vector_set.hpp:29
const std::size_t n
Definition: vector_set_test.cpp:26
bool empty() const
Definition: vector_set.hpp:35
value_type const & back() const
Definition: vector_set.hpp:33
Vector_set self_type
Definition: vector_set.hpp:21
const_iterator begin() const
Definition: vector_set.hpp:30
std::vector< T, Alloc > stor_t
Definition: vector_set.hpp:19
std::ptrdiff_t difference_type
Definition: vector_set.hpp:24
iterator begin()
Definition: vector_set.hpp:28
value_type const & operator[](const std::size_t n) const
Definition: vector_set.hpp:76
std::size_t size_type
Definition: vector_set.hpp:23
value_type & at(const std::size_t n)
Definition: vector_set.hpp:79
void pop_back()
Definition: vector_set.hpp:37
unsigned erase(CompatType const &t)
Definition: vector_set.hpp:58
bool operator<(self_type const &vs2) const
Definition: vector_set.hpp:82