#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <Sequence/bits/CountingOperators.tcc>
Go to the source code of this file.
Namespaces | |
| namespace | Sequence |
Functions | |
| bool | operator() (const std::pair< key, value > &l, const std::pair< key, value > &r) const |
| template<typename key, typename value> | |
| std::vector< std::pair< key, value > > | Sequence::operator+ (const std::vector< std::pair< key, value > > &lhs, const std::vector< std::pair< key, value > > &rhs) |
| template<typename key, typename value> | |
| std::vector< std::pair< key, value > > | Sequence::operator+= (std::vector< std::pair< key, value > > &lhs, const std::vector< std::pair< key, value > > &rhs) |
| template<typename key, typename value, typename comparison> | |
| std::map< key, value, comparison > | Sequence::operator+ (const std::map< key, value, comparison > &lhs, const std::map< key, value, comparison > &rhs) |
| template<typename key, typename value, typename comparison> | |
| std::map< key, value, comparison > | Sequence::operator+= (std::map< key, value, comparison > &lhs, const std::map< key, value, comparison > &rhs) |
A lot of biological computation involves counting. Associative containers such as vectors of pairs or maps (or hashes if you've got them) are natural data structures to keeps track of counts. However, keeping track of a running total of counts (say codon usage summed accross different sequences) is hampered by the lack of addition operators for associative containers. This file defines template operator+ and += for std::vector<std::pair<key,I> > and std::map<key,I>. The results of these operations are best explained by example:
#include <Sequence/CountingOperators.hpp> #include <map> std::map<char,unsigned> baseCounts,baseCounts2; baseCounts['A'] = 5; baseCounts['G'] = 10; baseCounts2['A'] = 11; baseCounts2['C'] = 17; std::map<char,unsigned> baseCounts3 = baseCounts + baseCounts2; for (std::map<char,unsigned>::const_iterator i = baseCounts3.begin() ; i != baseCounts3.end() ; ++i) { std::cout << i->first << '\t' << i->second << '\n'; }
Therefore, the result of the addition operation is an associative container containing all the "key" elements of the 2 containers being added. And when those containers contain common keys, the values associated with those keys are summed.
These operators are not restricted in terms of types for the template arguments. The only requirements are that operator== is defined for the key, and operator+ must be valid for the value type.
Definition in file CountingOperators.hpp.
| bool operator() | ( | const std::pair< key, value > & | l, | |
| const std::pair< key, value > & | r | |||
| ) | const [inline] |
Definition at line 84 of file CountingOperators.hpp.
1.5.6