本文整理汇总了C++中HashIterator类的典型用法代码示例。如果您正苦于以下问题:C++ HashIterator类的具体用法?C++ HashIterator怎么用?C++ HashIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HashIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_update
void CoroutineService::on_update(const int64_t now){
Super::on_update(now);
// wakeup sleeper
if(m_sleeper_table->size() > 0){
// prepare wake up list
Int64Array* wake_list =0;
HashIterator* it =static_cast< HashIterator* >(m_sleeper_table->iterator());
while(it->next()){
Int64* cr_id =static_cast< Int64* >(it->getKey());
Int64* expire_time =static_cast< Int64* >(it->getValue());
if(expire_time->getValue() > now){
if(!wake_list){
wake_list =SafeNew<Int64Array>();
}
wake_list->push_back(cr_id->getValue());
it->remove();
}
}
// wake up
const int64_t n =wake_list ? wake_list->size() : 0;
for(int64_t i=0; i<n; ++i){
_resume_coroutine(wake_list->get(i), SafeNew<Error>(ErrorCode::TIMEOUT), 0);
}
}
// update
int64_t cr_new_id=0;
m_cr_pool->go(_update, 0, cr_new_id);
}
示例2: GetMetaValue
int Ardb::HashLen(Context& ctx, const Slice& key)
{
ValueObject meta;
int err = GetMetaValue(ctx, key, HASH_META, meta);
CHECK_ARDB_RETURN_VALUE(ctx.reply, err);
if (err == ERR_NOT_EXIST)
{
fill_int_reply(ctx.reply, 0);
}
else
{
if (meta.meta.Length() < 0)
{
HashIterator iter;
meta.meta.len = 0;
HashIter(ctx, meta, "", iter, true);
while (iter.Valid())
{
meta.meta.len++;
iter.Next();
}
SetKeyValue(ctx, meta);
}
fill_int_reply(ctx.reply, meta.meta.Length());
}
return 0;
}
示例3: ASSERT
void CoroutinePool::finalize(){
m_cleaning =true;
// clean idle list
for(int64_t i=0; i<m_idle_coroutine_list->size(); ++i){
Coroutine* cr =static_cast< Coroutine* >(m_idle_coroutine_list->get(i));
cr->resume(SafeNew<Error>(ErrorCode::COROUTINE_CLEAN), 0);
ASSERT(cr->getStatus() == Coroutine::STATUS_DEAD);
}
CLEAN_POINTER(m_idle_coroutine_list);
// clean active table
Hash* active_cr_tb =m_active_coroutine_table;
m_active_coroutine_table =0;
HashIterator* it =static_cast< HashIterator* >(active_cr_tb->iterator());
while(it->next()){
Coroutine* cr =static_cast< Coroutine* >(it->getValue());
cr->resume(SafeNew<Error>(ErrorCode::COROUTINE_CLEAN), 0);
ASSERT(cr->getStatus() == Coroutine::STATUS_DEAD);
}
CLEAN_POINTER(active_cr_tb);
// super
Super::finalize();
}
示例4: forEach
void Hash::forEach(void (*pfn)(Object*, Object*, void*), void* userdata){
if(!pfn) return;
HashIterator* it =dynamic_cast<HashIterator*>(iterator());
while(it->next()){
pfn(it->getKey(), it->getValue(), userdata);
}
}
示例5: getAllComponent
Array* Actor::getAllComponent(){
Array* ret =SafeNew<Array>();
HashIterator* it =static_cast< HashIterator* >(m_component_manager->iterator());
while(it->next()){
ret->push_back(it->getValue());
}
return ret;
}
示例6:
status_t
Directory::Rewind(void *cookie)
{
HashIterator *iterator = (HashIterator *)cookie;
iterator->Rewind();
return B_OK;
}
示例7:
Object * Hash::clone(){
Hash* new_obj =core::SafeNew<Hash>();
HashIterator* it =dynamic_cast<HashIterator*>(this->iterator());
while(it->next()){
new_obj->set(it->getKey(), it->getValue());
}
return new_obj;
}
示例8: removeIf
void Hash::removeIf(bool (*pfn)(Object*, Object*)){
if(!pfn) return;
HashIterator* it =dynamic_cast<HashIterator*>(iterator());
while(it->next()){
if(pfn(it->getKey(), it->getValue())){
it->remove();
}
}
}
示例9: _optimize
void CommandService::_optimize(const int64_t now) {
if(m_queue_tb->size() > OPTIMIZE_THRESHOLD) {
HashIterator* it =static_cast< HashIterator* >(m_queue_tb->iterator());
while(it->next()) {
Array* queue =static_cast< Array* >(it->getValue());
if(queue->empty()) {
it->remove();
}
}
m_queue_tb->optimize(0);
}
}
示例10: guard
int Ardb::HClear(Context& ctx, ValueObject& meta)
{
BatchWriteGuard guard(GetKeyValueEngine(), meta.meta.encoding != COLLECTION_ECODING_ZIPMAP);
if (meta.meta.encoding != COLLECTION_ECODING_ZIPMAP)
{
HashIterator iter;
HashIter(ctx, meta, "", iter, false);
while (iter.Valid())
{
DelRaw(ctx, iter.CurrentRawKey());
iter.Next();
}
}
DelKeyValue(ctx, meta.key);
return 0;
}
示例11: while
void CommandService::_process_timeout(const int64_t now) {
/* clear timeout command */
if(m_queue_tb->size()>0) {
Int64Array* ls =0;
HashIterator* it =static_cast< HashIterator* >(m_queue_tb->iterator());
while(it->next()) {
const int64_t who =static_cast< Int64* >(it->getKey())->getValue();
Array* queue =static_cast< Array* >(it->getValue());
while(Command* cmd =dynamic_cast< Command* >(queue->front())) {
if(cmd->isTimeout(now)) {
if(cmd->isProcessing()) {
WARN("service %s(%lld) who %lld command %lld cancel", name(), (long long)m_id, (long long)cmd->getWho(), (long long)cmd->getCommand());
}
queue->pop_front();
}
else {
break;
}
}
if(Command* cmd =dynamic_cast< Command* >(queue->front())) {
if(cmd->isProcessing()) {
continue;
}
ASSERT(cmd->isInit());
if(!ls) {
ls =SafeNew<Int64Array>();
}
ls->push_back(who);
}
}
const int64_t n= ls ? ls->size() : 0;
for(int64_t i=0; i<n; ++i) {
_process_request(ls->get(i));
}
}
/* clear timeout rpc */
if(m_rpc_tb->size()>0) {
Array* ls =0;
HashIterator* it =static_cast< HashIterator* >(m_rpc_tb->iterator());
while(it->next()) {
RpcInfo* ri =static_cast< RpcInfo* >(it->getValue());
if(now >= ri->getExpireTime()) {
if(!ls) {
ls =SafeNew<Array>();
}
ls->push_back(ri);
it->remove();
}
}
const int64_t n =ls ? ls->size() : 0;
for(int64_t i=0; i<n; ++i) {
RpcInfo* ri =static_cast< RpcInfo* >(ls->get(i));
WARN("service %s(%lld) rpc %lld cancel", name(), (long long)m_id, (long long)ri->getId());
ri->timeout();
}
}
}
示例12: new
status_t
Directory::Open(void **_cookie, int mode)
{
_inherited::Open(_cookie, mode);
HashIterator *iterator = new(nothrow) HashIterator(fVolume.Device(), fNode);
if (iterator == NULL)
return B_NO_MEMORY;
if (iterator->InitCheck() != B_OK) {
delete iterator;
return B_NO_MEMORY;
}
*_cookie = (void *)iterator;
return B_OK;
}
示例13: guard
Int64Array* ServiceManager::_get_need_unload_service_id(){
std::lock_guard<LOCK_TYPE> guard(m_lock);
if(m_unloading_service_tb->empty()){
return 0;
}
const int64_t now =DateTime::Now();
Int64Array* arr =SafeNew<Int64Array>();
HashIterator* it =static_cast< HashIterator* >(m_unloading_service_tb->iterator());
while(it->next()){
const int64_t id_srv =static_cast< Int64* >(it->getKey())->getValue();
const int64_t t =static_cast< Int64* >(it->getValue())->getValue();
if(now >= t){
arr->push_back(id_srv);
it->remove();
}
}
return arr;
}
示例14: OPH
void ServiceManager::unloadAllService(){
OPH();
// prepare service table
Hash* srv_tb =0;
{
std::lock_guard<LOCK_TYPE> guard(m_lock);
srv_tb =static_cast< Hash* >(m_service_tb->clone());
m_service_tb->clear();
m_route_tb->clear();
m_unloading_service_tb->clear();
}
// unload
HashIterator* it =static_cast< HashIterator* >(srv_tb->iterator());
while(it->next()){
Service* service =static_cast< Service* >(it->getValue());
if(service){
service->unload();
}
}
srv_tb->clear();
}
示例15: update
/** coroutine manager **/
void CoroutinePool::update(const int64_t now){
// process timeout
if(m_active_coroutine_table && m_active_coroutine_table->size()>0){
// prepare
Int64Array* ls =0;
HashIterator* it =static_cast< HashIterator* >(m_active_coroutine_table->iterator());
while(it->next()){
Coroutine* cr =static_cast< Coroutine* >(it->getValue());
if(cr->isWaitingAndExpire(now)){
if(!ls){
ls =SafeNew<Int64Array>();
}
ls->push_back(cr->getId());
}
}
// resume
if(ls && ls->size()>0){
const int64_t n =ls->size();
for(int64_t i=0; i<n; ++i){
resume(ls->get(i), SafeNew<Error>(ErrorCode::TIMEOUT), 0);
}
}
}
}