From ead8845217c5e6e48f3680ead6f859ec8e110eb2 Mon Sep 17 00:00:00 2001 From: graehl Date: Fri, 13 Aug 2010 08:20:47 +0000 Subject: (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 --- utils/hash.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'utils/hash.h') 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(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 +bool improve_mapped_max(H &ht,K const& k,typename H::mapped_type const& v) { + std::pair inew=ht.insert(typename H::value_type(k,v)); + if (inew.second) return true; + typedef typename H::mapped_type V; + V &oldv=const_cast(inew.first->second); + if (oldv +bool improve_mapped_min(H &ht,K const& k,typename H::mapped_type const& v) { + std::pair inew=ht.insert(typename H::value_type(k,v)); + if (inew.second) return true; + typedef typename H::mapped_type V; + V &oldv=const_cast(inew.first->second); + if (v