bool Stasher::put(const void *key, uint32_t klen, const void *value, uint32_t vlen) { uint32_t hash32; Bucket bucket; int ret; if (!klen || !vlen) return false; hash32 = m_hashfunc(key, klen); m_array->get(bucket, address(hash32)); ret = bucket.append(hash32, key, klen, value, vlen, m_hhb->get_dupes(), m_hhb->get_maxrec()); if (ret == Bucket::APPEND_OVERFLOW) split_bucket(); else if (ret == Bucket::APPEND_CONFLICT) return false; m_hhb->set_itemcount(m_hhb->get_itemcount() + 1); return true; }
QList<int> Solver::BucketDiv(int lengthDiv,int bucketNum) { QMap<int,Bucket>temporaryBucket; //初始化bucketNum个桶 for(int i=0;i<=bucketNum;++i){ Bucket list; temporaryBucket.insert(i,list); } //将原始数据分到不同的桶中. for(int i=0;i<list.length();++i){ int index=(int)(list.at(i)/lengthDiv);//求出数值对应的桶号 //将数值装入桶中 Bucket bucket; bucket=temporaryBucket.value(index);//QMap中的value返回类型是const T bucket.append(list.at(i)); temporaryBucket.insert(index,bucket); } //对每个桶中元素进行排序 for(int i=0;i<=bucketNum;++i){ Bucket bucket=temporaryBucket.value(i); InsertSort(bucket); temporaryBucket.insert(i,bucket); } //合并各个桶中的数据 QList<int>temporaryList; for(int i=0;i<=bucketNum;++i){ temporaryList=temporaryList+temporaryBucket.value(i); } return temporaryList; }