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:
21  typedef Vector_set self_type;
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_;}
83  VDJ_PIPE_COMPARISON_OPERATOR_MEMBERS(self_type)
84 
85 private:
86  stor_t v_;
87 };
88 
89 }//namespace detail
90 }//namespace vdj_pipe
91 #endif /* VECTOR_SET_HPP_ */
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
Main namespace of vdj_pipe library.
Definition: sequence_file.hpp:14