00001 // -*- c++ -*- 00002 #pragma once 00003 #include <time.h> 00004 #include "moses/TargetPhraseCollection.h" 00005 #include <boost/atomic.hpp> 00006 #include "mm/ug_typedefs.h" 00007 namespace Moses 00008 { 00009 00010 class TPCollWrapper; 00011 00012 class TPCollCache 00013 { 00014 public: 00015 // typedef boost::unordered_map<uint64_t, SPTR<TPCollWrapper> > cache_t; 00016 typedef std::map<uint64_t, SPTR<TPCollWrapper> > cache_t; 00017 private: 00018 uint32_t m_capacity; // capacity of cache 00019 cache_t m_cache; // maps from ids to items 00020 cache_t::iterator m_qfirst, m_qlast; 00021 mutable boost::shared_mutex m_lock; 00022 public: 00023 TPCollCache(size_t capacity=10000); 00024 00025 SPTR<TPCollWrapper> 00026 get(uint64_t key, size_t revision); 00027 00028 }; 00029 00030 // wrapper around TargetPhraseCollection with reference counting 00031 // and additional members for caching purposes 00032 class TPCollWrapper 00033 : public TargetPhraseCollection 00034 { 00035 friend class TPCollCache; 00036 friend class Mmsapt; 00037 public: 00038 TPCollCache::cache_t::iterator prev, next; 00039 public: 00040 mutable boost::shared_mutex lock; 00041 size_t const revision; // rev. No. of the underlying corpus 00042 uint64_t const key; // phrase key 00043 TPCollWrapper(uint64_t const key, size_t const rev); 00044 ~TPCollWrapper(); 00045 }; 00046 00047 }