예제 #1
0
/**
 * Creates an index, and buckets and sorts the list of records into the index.
 */
void AlphabeticIndex::initBuckets(UErrorCode &errorCode) {
    if (U_FAILURE(errorCode) || buckets_ != NULL) {
        return;
    }
    buckets_ = createBucketList(errorCode);
    if (U_FAILURE(errorCode) || inputList_ == NULL || inputList_->isEmpty()) {
        return;
    }

    // Sort the records by name.
    // Stable sort preserves input order of collation duplicates.
    inputList_->sortWithUComparator(recordCompareFn, collator_, errorCode);

    // Now, we traverse all of the input, which is now sorted.
    // If the item doesn't go in the current bucket, we find the next bucket that contains it.
    // This makes the process order n*log(n), since we just sort the list and then do a linear process.
    // However, if the user adds an item at a time and then gets the buckets, this isn't efficient, so
    // we need to improve it for that case.

    Bucket *currentBucket = getBucket(*buckets_->bucketList_, 0);
    int32_t bucketIndex = 1;
    Bucket *nextBucket;
    const UnicodeString *upperBoundary;
    if (bucketIndex < buckets_->bucketList_->size()) {
        nextBucket = getBucket(*buckets_->bucketList_, bucketIndex++);
        upperBoundary = &nextBucket->lowerBoundary_;
    } else {
        nextBucket = NULL;
        upperBoundary = NULL;
    }
    for (int32_t i = 0; i < inputList_->size(); ++i) {
        Record *r = getRecord(*inputList_, i);
        // if the current bucket isn't the right one, find the one that is
        // We have a special flag for the last bucket so that we don't look any further
        while (upperBoundary != NULL &&
                collatorPrimaryOnly_->compare(r->name_, *upperBoundary, errorCode) >= 0) {
            currentBucket = nextBucket;
            // now reset the boundary that we compare against
            if (bucketIndex < buckets_->bucketList_->size()) {
                nextBucket = getBucket(*buckets_->bucketList_, bucketIndex++);
                upperBoundary = &nextBucket->lowerBoundary_;
            } else {
                upperBoundary = NULL;
            }
        }
        // now put the record into the bucket.
        Bucket *bucket = currentBucket;
        if (bucket->displayBucket_ != NULL) {
            bucket = bucket->displayBucket_;
        }
        if (bucket->records_ == NULL) {
            bucket->records_ = new UVector(errorCode);
            if (bucket->records_ == NULL) {
                errorCode = U_MEMORY_ALLOCATION_ERROR;
                return;
            }
        }
        bucket->records_->addElement(r, errorCode);
    }
}
예제 #2
0
void
ApplyBucketsWork::onReset()
{
    mTotalBuckets = 0;
    mAppliedBuckets = 0;
    mAppliedEntries = 0;
    mTotalSize = 0;
    mAppliedSize = 0;
    mLastAppliedSizeMb = 0;
    mLastPos = 0;

    auto addBucket = [this](std::shared_ptr<Bucket const> const& bucket) {
        if (bucket->getSize() > 0)
        {
            mTotalBuckets++;
            mTotalSize += bucket->getSize();
        }
    };

    for (auto const& hsb : mApplyState.currentBuckets)
    {
        addBucket(getBucket(hsb.snap));
        addBucket(getBucket(hsb.curr));
    }

    mLevel = BucketList::kNumLevels - 1;
    mApplying = false;
    mSnapBucket.reset();
    mCurrBucket.reset();
    mSnapApplicator.reset();
    mCurrApplicator.reset();
}
예제 #3
0
void World::queryLine(point_t v1, point_t v2, QueryCallback* qc) {
	if (use_partitioning) {
		//spatial hash version: check every rect in bucket intersecting line
		int min_x = (v1.getX()) / bucket_width;
		int max_x = (v2.getX()) / bucket_width;
		if (min_x > max_x)
			std::swap(min_x, max_x);
		int min_y = (v1.getY()) / bucket_height;
		int max_y = (v2.getY()) / bucket_height;
		if (min_y > max_y)
			std::swap(min_y, max_y);

		//todo: iterates over full box containing line; just iterate over any bucket intersecting.
		//iterate over all buckets intersecting line:
		for (int i = min_x; i <= max_x; i++)
			for (int j = min_y; j <= max_y; j++)
				if (bucket* b = getBucket(i, j))
					//iterate over all rects in bucket:
					for (auto iter : b->rect_v)
						//check if rect intersects the line:
						if (iter->queryOnLine(v1, v2))
							//halt if QueryCallback returns false.
							if (!qc->onMatch(iter,
									iter->getContactPointOnLine(v1, v2)))
								return;
	} else {
		//non spatial hash version: check every rect
		for (auto iter : v_rect) {
			if (iter->queryOnLine(v1, v2))
				if (!qc->onMatch(iter, iter->getContactPointOnLine(v1, v2)))
					return;
		}
	}
}
예제 #4
0
파일: hashMap.c 프로젝트: aniketsr/DSA
int put(HashMap* map,void* key,void* value){
    List* Bucket = getBucket(map,key);
    hashElement* element =calloc(1,sizeof(hashElement));
    element->key =key;
    element->value =value;
    return insert(Bucket,Bucket->length,element);
};
예제 #5
0
void World::queryRectangle(prec_t x, prec_t y, prec_t w, prec_t h, QueryCallback* qc) {
	if (use_partitioning) {
		//spatial hash version: check every rect in a bucket intersecting query rectangle
		int min_x = (x) / bucket_width;
		int max_x = (x + w) / bucket_width;
		int min_y = (y) / bucket_height;
		int max_y = (y + h) / bucket_height;
		//iterate through all buckets in rectangle:
		for (int i = min_x; i <= max_x; i++)
			for (int j = min_y; j <= max_y; j++)
				if (bucket* b = getBucket(i, j))
					//iterate through all rects in bucket:
					for (auto iter : b->rect_v)
						//see if rect intersects query rectangle
						if (iter->queryIntersects(x, y, w, h))
							//halt if onMatch() returns false (see QueryCallback)
							if (!qc->onMatch(iter,{0,0}))
								return;
	} else {
		//non spatial hash version: check every rect
		for (auto iter : v_rect) {
			if (iter->queryIntersects(x, y, w, h))
				if (!qc->onMatch(iter,{0,0}))
					return;
		}
	}
}
예제 #6
0
 virtual string dupKeyError(const IndexCatalogEntry* btreeState,
                            DiskLoc bucket,
                            const BSONObj& keyObj) const {
     typename Version::KeyOwned key(keyObj);
     return getBucket( btreeState, bucket )->dupKeyError(btreeState->descriptor(),
                                                         key);
 }
예제 #7
0
 virtual DiskLoc advance(const IndexCatalogEntry* btreeState,
                         const DiskLoc& thisLoc,
                         int& keyOfs,
                         int direction,
                         const char* caller) const {
     return getBucket( btreeState, thisLoc )->advance(thisLoc, keyOfs, direction, caller);
 }
예제 #8
0
				std::vector<IdType> getNearest(const IdType& id, size_t maxGroupSize = MAX_BUCKET_SIZE) const {
					std::lock_guard<std::mutex> lock(mutex_);
					
					const size_t index = getBucket(id);
					std::vector<IdType> group;
					
					for (size_t dist = 0; dist < IdType::SIZE_IN_BITS && group.size() < maxGroupSize; dist++) {
						if (index >= dist) {
							for (const auto& nodeId: buckets_.at(index - dist)) {
								if (group.size() >= maxGroupSize) {
									break;
								}
								group.push_back(nodeId);
							}
						}
						
						const auto rightPosition = index + dist + 1;
						if (rightPosition < IdType::SIZE_IN_BITS) {
							for (const auto& nodeId: buckets_[rightPosition]) {
								if (group.size() >= maxGroupSize) {
									break;
								}
								group.push_back(nodeId);
							}
						}
					}
					
					return group;
				}
예제 #9
0
void BucketSkipList::moveNodeToProperBucket(long nodeId, long oldCost) {
	BucketListElement* bucket = getBucket(oldCost);
	NodeListElement* foundNodeElement = NULL;
	if(bucket->nodes->node->id == nodeId) {
		foundNodeElement = bucket->nodes;
		bucket->nodes = foundNodeElement->next;
	} else {
		NodeListElement* lastElement = bucket->nodes;
		while(lastElement->next != NULL) {
			if(lastElement->next->node->id == nodeId) {
				foundNodeElement = lastElement->next;
				lastElement->next = foundNodeElement->next;
				break;
			}
			lastElement = lastElement->next;
		}
	}

	if(foundNodeElement == NULL) {
		cout << "F**k. Haven't found the node" << endl;
		exit(69);
	}

	insertNode(foundNodeElement);
}
예제 #10
0
inline
C *
NdbLinHash<C>::deleteKey ( const char* str, Uint32 len){
  const Uint32 hash = Hash(str, len);
  int dir, seg;
  getBucket(hash, &dir, &seg);
  
  NdbElement_t<C> *oldChain = 0;
  NdbElement_t<C> **chainp = &directory[dir]->elements[seg];
  for(NdbElement_t<C> * chain = *chainp; chain != 0; chain = chain->next){
    if(chain->len == len && !memcmp(chain->str, str, len)){
      C *data= chain->theData;
      if (oldChain == 0) {
	* chainp = chain->next;
      } else {
	oldChain->next = chain->next;
      }
      delete chain;
      return data;
    } else {
      oldChain = chain;
    }
  }
  return 0; /* Element doesn't exist */
}
예제 #11
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_DPSTRANSLOCK_TRYUPGRADE, "dpsTransLock::tryUpgrade" )
   INT32 dpsTransLock::tryUpgrade( _pmdEDUCB *eduCB,
                                   const dpsTransLockId &lockId,
                                   dpsTransCBLockInfo *pLockInfo,
                                   DPS_TRANSLOCK_TYPE lockType )
   {
      SDB_ASSERT( eduCB, "eduCB can't be null" ) ;
      INT32 rc = SDB_OK;
      DPS_TRANSLOCK_TYPE lastLockType;
      dpsLockBucket *pLockBucket = NULL;

      rc = upgradeCheck( pLockInfo->getType(), lockType );
      PD_RC_CHECK( rc, PDERROR, "Upgrade lock failed(rc=%d)", rc );

      rc = getBucket( lockId, pLockBucket );
      PD_RC_CHECK( rc, PDERROR, "Failed to get lock-bucket, upgrade lock "
                   "failed(rc=%d)", rc );

      lastLockType = pLockInfo->getType();
      pLockInfo->setType( lockType );
      rc = pLockBucket->tryAcquire( eduCB, lockId, lockType );
      PD_CHECK( SDB_OK == rc, rc, rollbackType, PDERROR,
                "Upgrade lock failed(rc=%d)", rc );

   done:
      PD_TRACE_EXIT ( SDB_DPSTRANSLOCK_TRYUPGRADE );
      return rc;
   rollbackType:
      pLockInfo->setType( lastLockType );
   error:
      goto done;
   }
예제 #12
0
Node* BucketSkipList::getMinCostNode() {
	NodeListElement* minCostNodeElement;

	BucketListElement* firstBucket = getBucket(currentMinCost);
	if(firstBucket->nodes == NULL) {
		long distanceToNextEmptyBucket = 1;
		BucketListElement* currentBucket = firstBucket->next;
		while(currentBucket->nodes == NULL) {
			distanceToNextEmptyBucket++;
			currentBucket = currentBucket->next;
		}

		currentMinCost += distanceToNextEmptyBucket;
		offset = (offset + distanceToNextEmptyBucket) % listSize;

		minCostNodeElement = currentBucket->nodes;
		currentBucket->nodes = minCostNodeElement->next;
	} else {
		minCostNodeElement = firstBucket->nodes;
		firstBucket->nodes = minCostNodeElement->next;
	}

	Node* minCostNode = minCostNodeElement->node;
	delete minCostNodeElement;
	currentNumberOfNodes--;
	return minCostNode;
}
예제 #13
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_DPSTRANSLOCK_RELEASEALL, "dpsTransLock::releaseAll" )
   void dpsTransLock::releaseAll( _pmdEDUCB *eduCB )
   {
      SDB_ASSERT( eduCB, "eduCB can't be null" ) ;
      INT32 rc = SDB_OK;
      dpsLockBucket *pLockBucket = NULL;
      DpsTransCBLockList *pLockLst = eduCB->getLockList();
      DpsTransCBLockList::iterator iterLst = pLockLst->begin();
      while ( iterLst != pLockLst->end() )
      {
         rc = getBucket( iterLst->first, pLockBucket );
         if ( rc )
         {
            PD_LOG( PDWARNING, "Failed to get lock-bucket while release "
                    "lock(rc=%d)", rc );
         }
         else
         {
            pLockBucket->release( eduCB, iterLst->first );
         }

         SDB_OSS_DEL iterLst->second;
         pLockLst->erase( iterLst++ );
      }
      eduCB->clearLockList() ;
      PD_TRACE_EXIT ( SDB_DPSTRANSLOCK_RELEASEALL );
      return ;
   }
예제 #14
0
 BucketList(UVector *bucketList, UVector *publicBucketList)
         : bucketList_(bucketList), immutableVisibleList_(publicBucketList) {
     int32_t displayIndex = 0;
     for (int32_t i = 0; i < publicBucketList->size(); ++i) {
         getBucket(*publicBucketList, i)->displayIndex_ = displayIndex++;
     }
 }
예제 #15
0
void getCommands(char* speedByte, char* turnByte)
{
   char bL=getBucket(LEFT);
   char bR=getBucket(RIGHT);
   *turnByte = (bR-bL) * 40;
   if(revDown())
   {
      //printf("revdown\r\n");
      *speedByte = (bL > bR)? -bL:-bR; //max function (on magnitudes)
   } 
   else
   {
      *speedByte = (bL > bR)? bL:bR; //max function
   }
   *speedByte *= 40;
   //printf("Spd: %i, Turn: %i",*speedByte,*turnByte);  
}                                                               
예제 #16
0
void addHostList(HostList *list)
{
   if(list == NULL) return;
   Bucket *bucket = getBucket(list); 
   /* The passed list is expected to exist in the host table. */
   assert(bucket != NULL);
   bucket->reference_count++;
}
예제 #17
0
파일: LTdecoder.c 프로젝트: day7th/libLT
unsigned int receiveSymb_BucketName(LTdecoder *decoder, int bucketName,
                                    char *encodedInfo, unsigned int encodedInfoLength,
                                    unsigned int IDfirstSymb) {

    Bucket *bucket = getBucket(decoder, bucketName);

    return genRXSymb(bucket, encodedInfo, encodedInfoLength,
                     &(decoder->RXsymbList), &(decoder->lastRXsymbol), IDfirstSymb);
}
예제 #18
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_DPSTRANSLOCK_ACQUIREIS, "dpsTransLock::acquireIS" )
   INT32 dpsTransLock::acquireIS( _pmdEDUCB *eduCB,
                                  const dpsTransLockId &lockId )
   {
      SDB_ASSERT( eduCB, "eduCB can't be null" ) ;
      SDB_ASSERT( ( DMS_INVALID_OFFSET == lockId._recordOffset
                  && DMS_INVALID_EXTENT == lockId._recordExtentID ),
                  "IX-Lock only used for collection or collectionspace" ) ;

      INT32 rc = SDB_OK;
      dpsLockBucket *pLockBucket = NULL;
      dpsTransLockId sLockId;
      dpsTransCBLockInfo *pLockInfo = NULL;
      BOOLEAN isISLocked = FALSE;

      if ( lockId._collectionID != DMS_INVALID_MBID )
      {
         sLockId._logicCSID = lockId._logicCSID;
         rc = acquireIS( eduCB, sLockId );
         PD_RC_CHECK( rc, PDERROR, "Failed to get the S-lock of space, "
                      "get IS-lock failed(rc=%d)", rc );
         isISLocked = TRUE;
      }

      pLockInfo = eduCB->getTransLock( lockId );
      if ( pLockInfo != NULL )
      {
         pLockInfo->incRef();
         goto done;
      }

      rc = getBucket( lockId, pLockBucket );
      PD_RC_CHECK( rc, PDERROR, "Failed to get the lock-bucket, "
                   "get IS-lock failed(rc=%d)", rc );

      {
      DPS_TRANS_WAIT_LOCK _transWaitLock( eduCB, lockId ) ;
      eduCB->addLockInfo( lockId, DPS_TRANSLOCK_IS );
      rc = pLockBucket->acquire( eduCB, lockId, DPS_TRANSLOCK_IS );
      }
      if ( rc )
      {
         eduCB->delLockInfo( lockId );
      }
      PD_RC_CHECK( rc, PDERROR, "Failed to get the IS-lock(rc=%d)", rc );

      PD_LOG( PDDEBUG, "Get the IS-lock(%s)", lockId.toString().c_str() );

   done:
      PD_TRACE_EXIT ( SDB_DPSTRANSLOCK_ACQUIREIS );
      return rc;
   error:
      if ( isISLocked )
      {
         release( eduCB, sLockId );
      }
      goto done;
   }
예제 #19
0
 virtual bool unindex(IndexCatalogEntry* btreeState,
                      const DiskLoc thisLoc,
                      const BSONObj& key,
                      const DiskLoc recordLoc) {
     return getBucket( btreeState, thisLoc )->unindex(btreeState,
                                                             thisLoc,
                                                             key,
                                                             recordLoc);
 }
예제 #20
0
	// recursive function which does all search logic
	void DFBBMonteCarlo(StarcraftStateType & s, int depth)
	{		
	    
		printf("Depth %d\n", depth);
	
		// increase the node expansion count
		nodesExpanded++;
		
		
		// the time at which the last thing in the queue will finish
		int finishTime = s.getLastFinishTime();
		
		if (finishTime >= upperBound)
		{
		    return;
		}
		
		int bucket = getBucket(finishTime);
		int armyValue = s.getArmyValue();
		
		if (armyValue > armyValues[bucket])
		{
		    armyValues[bucket] = armyValue;
		    buildOrders[bucket] = getBuildOrder(s);
		}
		
		// if we are using search timeout and we are over the limit
		if (params.searchTimeLimit && (nodesExpanded % 1000 == 0) && (searchTimer.getElapsedTimeInMilliSec() > params.searchTimeLimit))
		{
			// throw an exception to unroll the recursion
			throw 1;
		}
		
		// get the legal action set
		ActionSet legalActions = s.getLegalActionsMonteCarlo(params.goal); 

		// if we have children, update the counter
		if (!legalActions.isEmpty())
		{
			numGenerations += 1;
			numChildren += legalActions.numActions();
			
			Action nextAction = legalActions.randomAction();
			
			StarcraftStateType child(s);
				
			int readyTime = child.resourcesReady(nextAction); 
			child.doAction(nextAction, readyTime);
			child.setParent(&s);
			DFBBMonteCarlo(child, depth+1);
		}
		else
		{
		    printf("No legal actions %d\n", depth);
		}
	}
예제 #21
0
void World::removeFromBuckets(Rect* r) {
	assert(use_partitioning);
	for (int i = r->x/bucket_width;i<=(r->x+r->w)/bucket_width;i++)
			for (int j = r->y/bucket_height;j<=(r->y+r->h)/bucket_height;j++) {
				//only adds a bucket if no bucket existed there before.
				bucket* b=getBucket(i,j);
				if (b)
					b->rect_v.remove(r);
			}
}
예제 #22
0
void
ApplyBucketsWork::startLevel()
{
    assert(isLevelComplete());

    CLOG(DEBUG, "History") << "ApplyBuckets : starting level " << mLevel;
    auto& level = getBucketLevel(mLevel);
    HistoryStateBucket const& i = mApplyState.currentBuckets.at(mLevel);

    bool applySnap = (i.snap != binToHex(level.getSnap()->getHash()));
    bool applyCurr = (i.curr != binToHex(level.getCurr()->getHash()));
    if (!mApplying && (applySnap || applyCurr))
    {
        uint32_t oldestLedger = applySnap
                                    ? BucketList::oldestLedgerInSnap(
                                          mApplyState.currentLedger, mLevel)
                                    : BucketList::oldestLedgerInCurr(
                                          mApplyState.currentLedger, mLevel);
        auto& lsRoot = mApp.getLedgerTxnRoot();
        lsRoot.deleteObjectsModifiedOnOrAfterLedger(oldestLedger);
    }

    if (mApplying || applySnap)
    {
        mSnapBucket = getBucket(i.snap);
        mSnapApplicator = std::make_unique<BucketApplicator>(
            mApp, mMaxProtocolVersion, mSnapBucket);
        CLOG(DEBUG, "History") << "ApplyBuckets : starting level[" << mLevel
                               << "].snap = " << i.snap;
        mApplying = true;
        mBucketApplyStart.Mark();
    }
    if (mApplying || applyCurr)
    {
        mCurrBucket = getBucket(i.curr);
        mCurrApplicator = std::make_unique<BucketApplicator>(
            mApp, mMaxProtocolVersion, mCurrBucket);
        CLOG(DEBUG, "History") << "ApplyBuckets : starting level[" << mLevel
                               << "].curr = " << i.curr;
        mApplying = true;
        mBucketApplyStart.Mark();
    }
}
예제 #23
0
 virtual bool wouldCreateDup(const IndexCatalogEntry* btreeState,
                             const DiskLoc& thisLoc,
                             const BSONObj& key,
                             const DiskLoc& self) const {
     typename Version::KeyOwned ownedVersion(key);
     return getBucket( btreeState, thisLoc )->wouldCreateDup(btreeState,
                                                                    thisLoc,
                                                                    ownedVersion,
                                                                    self);
 }
예제 #24
0
파일: hashMap.c 프로젝트: aniketsr/DSA
void dispose(HashMap* map){
    List* Bucket;
    int loop;
    for(loop=map->capacity;loop>0;loop--){
        Bucket = (List*)getBucket(map,&loop);
        if (Bucket == NULL) continue;
        if(Bucket->head!= NULL) 
        Free(Bucket);
    }
}; 
예제 #25
0
bool World::contains(Rect* target) {
	if (use_partitioning) {
		for (auto iter : getBucket(target->getX()/bucket_width,target->getY()/bucket_height)->rect_v)
			if (iter==target)
				return true;
	} else
		for (auto iter : v_rect)
			if (&*iter==target)
				return true;
	return false;
}
예제 #26
0
 virtual BSONObj keyAt(const IndexCatalogEntry* btreeState,
                       DiskLoc bucket, int keyOffset) const {
     verify(!bucket.isNull());
     const BtreeBucket<Version> *b = getBucket(btreeState,bucket);
     int n = b->getN();
     if (n == b->INVALID_N_SENTINEL) {
         throw UserException(deletedBucketCode, "keyAt bucket deleted");
     }
     dassert( n >= 0 && n < 10000 );
     return keyOffset >= n ? BSONObj() : b->keyNode(keyOffset).key.toBson();
 }
예제 #27
0
   //PD_TRACE_DECLARE_FUNCTION ( SDB_DPSTRANSLOCK_RELEASE, "dpsTransLock::release" )
   void dpsTransLock::release( _pmdEDUCB * eduCB,
                               const dpsTransLockId & lockId )
   {
      SDB_ASSERT( eduCB, "eduCB can't be null" ) ;
      INT32 rc = SDB_OK;
      dpsLockBucket *pLockBucket = NULL;
      dpsTransLockId iLockId;
      dpsTransCBLockInfo *pLockInfo = NULL;
      INT64 lockRef = 0;

      pLockInfo = eduCB->getTransLock( lockId );
      PD_CHECK( pLockInfo, SDB_OK, done, PDWARNING,
                "duplicate release lock(%s)",
                lockId.toString().c_str() ) ;
      lockRef = pLockInfo->decRef();
      if ( lockRef <= 0 )
      {
         rc = getBucket( lockId, pLockBucket );
         if ( rc )
         {
            PD_LOG( PDWARNING, "Failed to get lock-bucket while release "
                    "lock(rc=%d)", rc );
         }
         else
         {
            pLockBucket->release( eduCB, lockId );
         }

         eduCB->delLockInfo( lockId );
         pLockInfo = NULL;
      }

      if ( lockId._collectionID != DMS_INVALID_MBID )
      {
         iLockId = lockId;
         if ( lockId._recordOffset != DMS_INVALID_OFFSET )
         {
            iLockId._recordExtentID = DMS_INVALID_EXTENT;
            iLockId._recordOffset = DMS_INVALID_OFFSET;
            release( eduCB, iLockId );
         }
         else
         {
            iLockId._collectionID = DMS_INVALID_MBID;
            release( eduCB, iLockId );
         }
      }

   done:
      PD_TRACE_EXIT ( SDB_DPSTRANSLOCK_RELEASE );
      return ;
   }
예제 #28
0
 int32_t getBucketIndex(const UnicodeString &name, const Collator &collatorPrimaryOnly,
                        UErrorCode &errorCode) {
     // binary search
     int32_t start = 0;
     int32_t limit = bucketList_->size();
     while ((start + 1) < limit) {
         int32_t i = (start + limit) / 2;
         const AlphabeticIndex::Bucket *bucket = getBucket(*bucketList_, i);
         UCollationResult nameVsBucket =
             collatorPrimaryOnly.compare(name, bucket->lowerBoundary_, errorCode);
         if (nameVsBucket < 0) {
             limit = i;
         } else {
             start = i;
         }
     }
     const AlphabeticIndex::Bucket *bucket = getBucket(*bucketList_, start);
     if (bucket->displayBucket_ != NULL) {
         bucket = bucket->displayBucket_;
     }
     return bucket->displayIndex_;
 }
예제 #29
0
unsigned readEHTFile(EHTFILE * file, char * key) {
    unsigned recordPos = hash(key) % file->tableSize;
    char * ptr;
    int i;

    getBucket(file, recordPos);
    for ( i = 0, ptr = file->bucket->buffer; i < file->bucket->length; ++i, ptr += sizeof(unsigned) + file->keyLength ) {
		IndexOverlay * indexEntry = (IndexOverlay *)ptr;
        if ( strcmp(key, indexEntry->key) == 0 )
            return indexEntry->link;
	}
	return 0;
}
예제 #30
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_DPSTRANSLOCK_TESTX, "dpsTransLock::testX" )
   INT32 dpsTransLock::testX( _pmdEDUCB *eduCB, const dpsTransLockId &lockId )
   {
      SDB_ASSERT( eduCB, "eduCB can't be null" ) ;
      INT32 rc = SDB_OK;
      dpsLockBucket *pLockBucket = NULL;
      dpsTransLockId iLockId;
      dpsTransCBLockInfo *pLockInfo = NULL;

      pLockInfo = eduCB->getTransLock( lockId );
      if ( pLockInfo != NULL && pLockInfo->isLockMatch( DPS_TRANSLOCK_X ))
      {
         goto done;
      }

      if ( lockId._collectionID != DMS_INVALID_MBID )
      {
         iLockId = lockId ;
         if ( lockId._recordOffset != DMS_INVALID_OFFSET )
         {
            iLockId._recordExtentID = DMS_INVALID_EXTENT;
            iLockId._recordOffset = DMS_INVALID_OFFSET;
         }
         else
         {
            iLockId._collectionID = DMS_INVALID_MBID;
         }
         rc = testIX( eduCB, iLockId);
   
         PD_RC_CHECK( rc, PDINFO, "Failed to test the intention-lock, "
                      "test IX-lock failed(rc=%d)", rc );
      }

      if ( pLockInfo )
      {
         rc = testUpgrade( eduCB, lockId, pLockInfo, DPS_TRANSLOCK_X );
      }
      else
      {
         rc = getBucket( lockId, pLockBucket );
         PD_RC_CHECK( rc, PDERROR, "Failed to get the lock-bucket, "
                      "test X-lock failed(rc=%d)", rc );
         rc = pLockBucket->test( eduCB, lockId, DPS_TRANSLOCK_X );
      }
      PD_RC_CHECK( rc, PDINFO, "Failed to test the X-lock(rc=%d)", rc );

   done:
      PD_TRACE_EXIT ( SDB_DPSTRANSLOCK_TESTX );
      return rc;
   error:
      goto done;
   }