-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
399 additions
and
395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
#include <map> | ||
#include <functional> | ||
#include <memory> | ||
#include <boost/noncopyable.hpp> | ||
#include "spinlock.h" | ||
|
||
#pragma once | ||
|
||
namespace csi { | ||
namespace kafka { | ||
template<class key_type, class value_type, typename key_compare = std::less<key_type>> | ||
class table : public boost::noncopyable { | ||
public: | ||
typedef typename std::map<key_type, std::shared_ptr<value_type>, key_compare>::iterator iterator; | ||
typedef typename std::map<key_type, std::shared_ptr<value_type>, key_compare>::const_iterator const_iterator; | ||
|
||
void put(const key_type& key, std::shared_ptr<value_type> v) { | ||
csi::kafka::spinlock::scoped_lock xx(_spinlock); | ||
_data[key] = v; | ||
} | ||
|
||
std::shared_ptr<value_type> get(const key_type& key) const { | ||
csi::kafka::spinlock::scoped_lock xx(_spinlock); | ||
const_iterator item = _data.find(key); | ||
if(item != _data.end()) | ||
return item->second; | ||
return std::shared_ptr<value_type>(NULL); | ||
} | ||
|
||
size_t size() const { return _data.size(); } // skip the lock - it should be ok anyway | ||
|
||
private: | ||
mutable csi::kafka::spinlock _spinlock; | ||
std::map<key_type, std::shared_ptr<value_type>, key_compare> _data; | ||
}; | ||
} | ||
} | ||
//#include <map> | ||
//#include <functional> | ||
//#include <memory> | ||
//#include <boost/noncopyable.hpp> | ||
//#include "spinlock.h" | ||
// | ||
//#pragma once | ||
// | ||
//namespace csi { | ||
// namespace kafka { | ||
// template<class key_type, class value_type, typename key_compare = std::less<key_type>> | ||
// class table : public boost::noncopyable { | ||
// public: | ||
// typedef typename std::map<key_type, std::shared_ptr<value_type>, key_compare>::iterator iterator; | ||
// typedef typename std::map<key_type, std::shared_ptr<value_type>, key_compare>::const_iterator const_iterator; | ||
// | ||
// void put(const key_type& key, std::shared_ptr<value_type> v) { | ||
// csi::kafka::spinlock::scoped_lock xx(_spinlock); | ||
// _data[key] = v; | ||
// } | ||
// | ||
// std::shared_ptr<value_type> get(const key_type& key) const { | ||
// csi::kafka::spinlock::scoped_lock xx(_spinlock); | ||
// const_iterator item = _data.find(key); | ||
// if(item != _data.end()) | ||
// return item->second; | ||
// return std::shared_ptr<value_type>(NULL); | ||
// } | ||
// | ||
// size_t size() const { return _data.size(); } // skip the lock - it should be ok anyway | ||
// | ||
// private: | ||
// mutable csi::kafka::spinlock _spinlock; | ||
// std::map<key_type, std::shared_ptr<value_type>, key_compare> _data; | ||
// }; | ||
// } | ||
//} |
Oops, something went wrong.