diff options
author | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-08-13 08:20:47 +0000 |
---|---|---|
committer | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-08-13 08:20:47 +0000 |
commit | ead8845217c5e6e48f3680ead6f859ec8e110eb2 (patch) | |
tree | a9bd115c8b2b95f933d76e8deed37678b2baa280 /utils/hash.h | |
parent | 84009c98d9a0a2e3ecd801ebb92ed47ee3f3328b (diff) |
(NEEDS TESTING) cfg index rules->nts, sort by prob, remove duplicates keeping highest prob, topo sort (and after binarize topo sort). beginning to apply_fsa_models (PrefixTrieNode)
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@539 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'utils/hash.h')
-rwxr-xr-x | utils/hash.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/utils/hash.h b/utils/hash.h index e89b1863..b0b1c43e 100755 --- a/utils/hash.h +++ b/utils/hash.h @@ -58,4 +58,31 @@ typename H::mapped_type & get_default(H &ht,K const& k,typename H::mapped_type c return const_cast<typename H::mapped_type &>(ht.insert(typename H::value_type(k,v)).first->second); } +// the below could also return a ref to the mapped max/min. they have the advantage of not falsely claiming an improvement when an equal value already existed. otherwise you could just modify the get_default and if equal assume new. +template <class H,class K> +bool improve_mapped_max(H &ht,K const& k,typename H::mapped_type const& v) { + std::pair<typename H::iterator,bool> inew=ht.insert(typename H::value_type(k,v)); + if (inew.second) return true; + typedef typename H::mapped_type V; + V &oldv=const_cast<V&>(inew.first->second); + if (oldv<v) { + oldv=v; + return true; + } + return false; +} + +template <class H,class K> +bool improve_mapped_min(H &ht,K const& k,typename H::mapped_type const& v) { + std::pair<typename H::iterator,bool> inew=ht.insert(typename H::value_type(k,v)); + if (inew.second) return true; + typedef typename H::mapped_type V; + V &oldv=const_cast<V&>(inew.first->second); + if (v<oldv) { // the only difference from above + oldv=v; + return true; + } + return false; +} + #endif |