LocARNA-1.8.11
alphabet.hh
1 #ifndef LOCARNA_ALPHABET_HH
2 #define LOCARNA_ALPHABET_HH
3 
4 #ifdef HAVE_CONFIG_H
5 # include <config.h>
6 #endif
7 
8 #include <vector>
9 #include <map>
10 #include <iosfwd>
11 #include <assert.h>
12 
13 namespace LocARNA {
14 
22  template<class T>
23  class Alphabet {
24  typedef std::vector<T> vec_t;
25  public:
26  typedef typename vec_t::size_type size_type;
27  private:
28  typedef std::map<T,size_type> hash_t;
29 
30  vec_t alph_vec;
31  hash_t alph_hash;
32  public:
33  typedef size_type index_type;
34  typedef T elem_type;
35  typedef std::vector<T> elem_vector_type;
36 
38  typedef typename elem_vector_type::iterator iterator;
39 
41  typedef typename elem_vector_type::const_iterator const_iterator;
42 
44  Alphabet();
45 
47  explicit
48  Alphabet(const elem_vector_type &a);
49 
51  Alphabet(const elem_type *s,int len);
52 
54  size_type size() const;
55 
57  size_type idx(const elem_type &elem) const;
58 
64  const elem_type &
65  elem(size_type idx) const;
66 
68  bool
69  in(const elem_type &elem) const;
70 
72  const_iterator begin() const {return alph_vec.begin();}
73 
75  const_iterator end() const {return alph_vec.end();}
76 
78  iterator begin() {return alph_vec.begin();}
79 
81  iterator end() {return alph_vec.end();}
82 
83  private:
85  void init(const vec_t &a);
86  };
87 
96  template<class T>
97  std::ostream & operator << (std::ostream &out,Alphabet<T> a);
98 
99 }
100 
101 # include "alphabet.icc"
102 
103 #endif // LOCARNA_ALPHABET_HH
size_type index_type
type of index
Definition: alphabet.hh:33
elem_vector_type::iterator iterator
iterator over alphabet elements
Definition: alphabet.hh:38
Definition: aligner.cc:17
vec_t::size_type size_type
size type
Definition: alphabet.hh:26
const_iterator begin() const
begin for const iteration over elements
Definition: alphabet.hh:72
T elem_type
type of an alphabet element
Definition: alphabet.hh:34
iterator begin()
begin for iteration over elements
Definition: alphabet.hh:78
Specifies an alphabet.
Definition: alphabet.hh:23
std::vector< T > elem_vector_type
vector of elements
Definition: alphabet.hh:35
size_type size() const
get alphabet size
const elem_type & elem(size_type idx) const
convert index to element
const_iterator end() const
end for const iteration over elements
Definition: alphabet.hh:75
elem_vector_type::const_iterator const_iterator
const iterator over alphabet elements
Definition: alphabet.hh:41
bool in(const elem_type &elem) const
test membership in alphabet
iterator end()
end for iteration over elements
Definition: alphabet.hh:81
Alphabet()
construct empty
size_type idx(const elem_type &elem) const
convert element to index