IMPORTANT!!! We pass only the partition number, because we must make sure we get a fresh
partition reference. The partition reference used during search for the key may have become
invalid during the compaction.
496244
private void insertBucketEntryFromSearch(MemorySegment originalBucket, MemorySegment currentBucket,
												int originalBucketOffset, int currentBucketOffset,
												int countInCurrentBucket, long originalForwardPointer,
												int hashCode, long pointer, int partitionNumber) throws IOException {
		boolean checkForResize = false;
		if (countInCurrentBucket < NUM_ENTRIES_PER_BUCKET) {
			// we are good in our current bucket, put the values
			currentBucket.putInt(currentBucketOffset + BUCKET_HEADER_LENGTH + (countInCurrentBucket * HASH_CODE_LEN), hashCode); // hash code
			currentBucket.putLong(currentBucketOffset + BUCKET_POINTER_START_OFFSET + (countInCurrentBucket * POINTER_LEN), pointer); // pointer
			currentBucket.putInt(currentBucketOffset + HEADER_COUNT_OFFSET, countInCurrentBucket + 1); // update count
		}
		else {
			// we go to a new overflow bucket
			final InMemoryPartition<T> partition = this.partitions.get(partitionNumber);
			MemorySegment overflowSeg;
			final int overflowSegmentNum;
			final int overflowBucketOffset;
			
			// first, see if there is space for an overflow bucket remaining in the last overflow segment
			if (partition.nextOverflowBucket == 0) {
				// no space left in last bucket, or no bucket yet, so create an overflow segment
				overflowSeg = getNextBuffer();
				overflowBucketOffset = 0;
				overflowSegmentNum = partition.numOverflowSegments;
				
				// add the new overflow segment
				if (partition.overflowSegments.length <= partition.numOverflowSegments) {
					MemorySegment[] newSegsArray = new MemorySegment[partition.overflowSegments.length * 2];
					System.arraycopy(partition.overflowSegments, 0, newSegsArray, 0, partition.overflowSegments.length);
					partition.overflowSegments = newSegsArray;
				}
				partition.overflowSegments[partition.numOverflowSegments] = overflowSeg;
				partition.numOverflowSegments++;
				checkForResize = true;
			}
			else {
				// there is space in the last overflow segment
				overflowSegmentNum = partition.numOverflowSegments - 1;
				overflowSeg = partition.overflowSegments[overflowSegmentNum];
				overflowBucketOffset = partition.nextOverflowBucket << NUM_INTRA_BUCKET_BITS;
			}
			
			// next overflow bucket is one ahead. if the segment is full, the next will be at the beginning
			// of a new segment
			partition.nextOverflowBucket = (partition.nextOverflowBucket == this.bucketsPerSegmentMask ? 0 : partition.nextOverflowBucket + 1);
			
			// insert the new overflow bucket in the chain of buckets
			
			// 1) set the old forward pointer
			// 2) let the bucket in the main table point to this one
			overflowSeg.putLong(overflowBucketOffset + HEADER_FORWARD_OFFSET, originalForwardPointer);
			final long pointerToNewBucket = (((long) overflowSegmentNum) << 32) | ((long) overflowBucketOffset);
			originalBucket.putLong(originalBucketOffset + HEADER_FORWARD_OFFSET, pointerToNewBucket);
			
			// finally, insert the values into the overflow buckets
			overflowSeg.putInt(overflowBucketOffset + BUCKET_HEADER_LENGTH, hashCode);	// hash code
			overflowSeg.putLong(overflowBucketOffset + BUCKET_POINTER_START_OFFSET, pointer); // pointer
			
			// set the count to one
			overflowSeg.putInt(overflowBucketOffset + HEADER_COUNT_OFFSET, 1);
			if(checkForResize && !this.isResizing) {
				// check if we should resize buckets
				if(this.buckets.length <= getOverflowSegmentCount()) {
					resizeHashTable();
				}
			}
		}
	}
538555
public void deleteKey(String key) throws IOException {
        Path keyDir = getKeyDir(key);
        HdfsBlobStoreFile pf = new HdfsBlobStoreFile(keyDir, BLOBSTORE_DATA,
                _hadoopConf);
        pf.delete();
        delete(keyDir);
    }
620884
@SuppressWarnings("unchecked")
  public static <E> PartitionKey partitionKeyForEntity(PartitionStrategy strategy,
      E entity, EntityAccessor<E> accessor, @Nullable PartitionKey reuseKey) {
    List<FieldPartitioner> fieldPartitioners =
        Accessor.getDefault().getFieldPartitioners(strategy);

    PartitionKey key = (reuseKey == null ?
        new PartitionKey(new Object[fieldPartitioners.size()]) : reuseKey);

    for (int i = 0; i < fieldPartitioners.size(); i++) {
      FieldPartitioner fp = fieldPartitioners.get(i);
      key.set(i, fp.apply(accessor.get(entity, fp.getSourceName())));
    }
    return key;
  }
943102
def Search(self,key):
		

		results = []
		for disk in self.disks:
			if disk.id.lower().find(key.lower()) != -1:  results.append(disk)
			# TODO - search in list to match partial mount points
			elif key.lower() in disk.partition_paths:  results.append(disk)

		return(results)
730560
public int binarySearch(RowPosition key)
    {
        int low = 0, mid = offsetCount, high = mid - 1, result = -1;
        while (low <= high)
        {
            mid = (low + high) >> 1;
            result = -DecoratedKey.compareTo(partitioner, ByteBuffer.wrap(getKey(mid)), key);
            if (result > 0)
            {
                low = mid + 1;
            }
            else if (result == 0)
            {
                return mid;
            }
            else
            {
                high = mid - 1;
            }
        }

        return -mid - (result < 0 ? 1 : 2);
    }
837614
private Boolean containsKeyIntern(final ChunkCacheKey chunkCacheKey) throws IOException {
      try {
         final long length = directory.fileLength(chunkCacheKey.getFileName());
         final int bufferSize = chunkCacheKey.getBufferSize();
         final int chunkId = chunkCacheKey.getChunkId();
         return Boolean.valueOf((chunkId * bufferSize) < (length + bufferSize));
      }
      catch (NoSuchFileException nfne) {
         //Ok, we might check for file existence first.. but it's reasonable to be
         //optimistic.
         return Boolean.FALSE;
      }
   }
75612
private boolean findFirstSameBuildRow(
			MemorySegment bucket,
			int searchHashCode,
			int bucketInSegmentOffset,
			BinaryRow buildRowToInsert) {
		int posInSegment = bucketInSegmentOffset + BUCKET_HEADER_LENGTH;
		int countInBucket = bucket.getShort(bucketInSegmentOffset + HEADER_COUNT_OFFSET);
		int numInBucket = 0;
		RandomAccessInputView view = partition.getBuildStateInputView();
		while (countInBucket != 0) {
			while (numInBucket < countInBucket) {

				final int thisCode = bucket.getInt(posInSegment);
				posInSegment += HASH_CODE_LEN;

				if (thisCode == searchHashCode) {
					final int pointer = bucket.getInt(bucketInSegmentOffset +
							BUCKET_POINTER_START_OFFSET + (numInBucket * POINTER_LEN));
					numInBucket++;
					try {
						view.setReadPosition(pointer);
						BinaryRow row = table.binaryBuildSideSerializer.mapFromPages(table.reuseBuildRow, view);
						if (buildRowToInsert.equals(row)) {
							return true;
						}
					} catch (IOException e) {
						throw new RuntimeException("Error deserializing key or value from the hashtable: " +
								e.getMessage(), e);
					}
				} else {
					numInBucket++;
				}
			}

			// this segment is done. check if there is another chained bucket
			final int forwardPointer = bucket.getInt(bucketInSegmentOffset + HEADER_FORWARD_OFFSET);
			if (forwardPointer == BUCKET_FORWARD_POINTER_NOT_SET) {
				return false;
			}

			final int overflowSegIndex = forwardPointer >>> table.segmentSizeBits;
			bucket = overflowSegments[overflowSegIndex];
			bucketInSegmentOffset = forwardPointer & table.segmentSizeMask;
			countInBucket = bucket.getShort(bucketInSegmentOffset + HEADER_COUNT_OFFSET);
			posInSegment = bucketInSegmentOffset + BUCKET_HEADER_LENGTH;
			numInBucket = 0;
		}
		return false;
	}
119721
@Override
    public boolean shouldBackup() {
        NodeEngine nodeEngine = getNodeEngine();
        IPartitionService partitionService = nodeEngine.getPartitionService();
        Address thisAddress = nodeEngine.getThisAddress();
        IPartition partition = partitionService.getPartition(getPartitionId());
        if (!thisAddress.equals(partition.getOwnerOrNull())) {
            return false;
        }
        return super.shouldBackup();
    }
433485
@Override
    public boolean containsKey(Object key) {
        if (key == null) {
            throw new NullPointerException();
        }
        
        CachedValue<K, V> entry = map.get(key);
        if (entry == null) {
            return false;
        }
        if (isValueExpired(entry)) {
            if (map.remove(key, entry)) {
                onValueRemove(entry);
                return false;
            }
            return containsKey(key);
        }
        return true;
    }
1276754
public void containsEntry(@NullableDecl Object key, @NullableDecl Object value) {
    // TODO(kak): Can we share any of this logic w/ MapSubject.containsEntry()?
    if (!actual().containsEntry(key, value)) {
      Entry<Object, Object> entry = Maps.immutableEntry(key, value);
      List<Entry<Object, Object>> entryList = ImmutableList.of(entry);
      if (hasMatchingToStringPair(actual().entries(), entryList)) {
        failWithoutActual(
            simpleFact(
                lenientFormat(
                    "Not true that %s contains entry <%s (%s)>. However, it does contain entries "
                        + "<%s>",
                    actualAsString(),
                    entry,
                    objectToTypeName(entry),
                    countDuplicatesAndAddTypeInfo(
                        retainMatchingToString(
                            actual().entries(), entryList /* itemsToCheck */)))));
      } else if (actual().containsKey(key)) {
        failWithoutActual(
            simpleFact(
                lenientFormat(
                    "Not true that %s contains entry <%s>. However, it has a mapping from <%s> to "
                        + "<%s>",
                    actualAsString(), entry, key, actual().asMap().get(key))));
      } else if (actual().containsValue(value)) {
        Set<Object> keys = new LinkedHashSet<>();
        for (Entry<?, ?> actualEntry : actual().entries()) {
          if (Objects.equal(actualEntry.getValue(), value)) {
            keys.add(actualEntry.getKey());
          }
        }
        failWithoutActual(
            simpleFact(
                lenientFormat(
                    "Not true that %s contains entry <%s>. "
                        + "However, the following keys are mapped to <%s>: %s",
                    actualAsString(), entry, value, keys)));
      } else {
        failWithActual("expected to contain entry", Maps.immutableEntry(key, value));
      }
    }
  }
126093
int refreshAndGetMin() {
		int min = Integer.MAX_VALUE;

		ResultSubpartition[] allPartitions = partition.getAllPartitions();
		if (allPartitions.length == 0) {
			// meaningful value when no channels exist:
			return 0;
		}

		for (ResultSubpartition part : allPartitions) {
			int size = part.unsynchronizedGetNumberOfQueuedBuffers();
			min = Math.min(min, size);
		}

		return min;
	}
1220286
private void compactPartition(int partitionNumber) throws IOException {
		// stop if no garbage exists
		if(this.partitions.get(partitionNumber).isCompacted()) {
			return;
		}
		// release all segments owned by compaction partition
		this.compactionMemory.clearAllMemory(availableMemory);
		this.compactionMemory.allocateSegments(1);
		T tempHolder = this.buildSideSerializer.createInstance();
		InMemoryPartition<T> partition = this.partitions.remove(partitionNumber);
		final int numPartitions = this.partitions.size() + 1; // dropped one earlier
		long pointer = 0L;
		int pointerOffset = 0;
		int bucketOffset = 0;
		final int bucketsPerSegment = this.bucketsPerSegmentMask + 1;
		for (int i = 0, bucket = partitionNumber; i < this.buckets.length && bucket < this.numBuckets; i++) {
			MemorySegment segment = this.buckets[i];
			// go over all buckets in the segment belonging to the partition
			for (int k = bucket % bucketsPerSegment; k < bucketsPerSegment && bucket < this.numBuckets; k += numPartitions, bucket += numPartitions) {
				bucketOffset = k * HASH_BUCKET_SIZE;
				if((int)segment.get(bucketOffset + HEADER_PARTITION_OFFSET) != partitionNumber) {
					throw new IOException("Accessed wrong bucket! ");
				}
				int count = segment.getInt(bucketOffset + HEADER_COUNT_OFFSET);
				for (int j = 0; j < NUM_ENTRIES_PER_BUCKET && j < count; j++) {
					pointerOffset = bucketOffset + BUCKET_POINTER_START_OFFSET + (j * POINTER_LEN);
					pointer = segment.getLong(pointerOffset);
					partition.readRecordAt(pointer, tempHolder);
					pointer = this.compactionMemory.appendRecord(tempHolder);
					segment.putLong(pointerOffset, pointer);
				}
				long overflowPointer = segment.getLong(bucketOffset + HEADER_FORWARD_OFFSET);
				if(overflowPointer != BUCKET_FORWARD_POINTER_NOT_SET) {
					// scan overflow buckets
					int current = NUM_ENTRIES_PER_BUCKET;
					bucketOffset = (int) (overflowPointer & 0xffffffff);
					pointerOffset = ((int) (overflowPointer & 0xffffffff)) + BUCKET_POINTER_START_OFFSET;
					int overflowSegNum = (int) (overflowPointer >>> 32);
					count += partition.overflowSegments[overflowSegNum].getInt(bucketOffset + HEADER_COUNT_OFFSET);
					while(current < count) {
						pointer = partition.overflowSegments[overflowSegNum].getLong(pointerOffset);
						partition.readRecordAt(pointer, tempHolder);
						pointer = this.compactionMemory.appendRecord(tempHolder);
						partition.overflowSegments[overflowSegNum].putLong(pointerOffset, pointer);
						current++;
						if(current % NUM_ENTRIES_PER_BUCKET == 0) {
							count += partition.overflowSegments[overflowSegNum].getInt(bucketOffset + HEADER_COUNT_OFFSET);
							overflowPointer = partition.overflowSegments[overflowSegNum].getLong(bucketOffset + HEADER_FORWARD_OFFSET);
							if(overflowPointer == BUCKET_FORWARD_POINTER_NOT_SET) {
								break;
							}
							overflowSegNum = (int) (overflowPointer >>> 32);
							bucketOffset = (int) (overflowPointer & 0xffffffff);
							pointerOffset = ((int) (overflowPointer & 0xffffffff)) + BUCKET_POINTER_START_OFFSET;
						} else {
							pointerOffset += POINTER_LEN;
						}
					}
				}
			}
		}
		// swap partition with compaction partition
		this.compactionMemory.setPartitionNumber(partitionNumber);
		this.partitions.add(partitionNumber, compactionMemory);
		this.compactionMemory = partition;
		this.partitions.get(partitionNumber).overflowSegments = this.compactionMemory.overflowSegments;
		this.partitions.get(partitionNumber).numOverflowSegments = this.compactionMemory.numOverflowSegments;
		this.partitions.get(partitionNumber).nextOverflowBucket = this.compactionMemory.nextOverflowBucket;
		this.partitions.get(partitionNumber).setCompaction(true);
		this.compactionMemory.resetRecordCounter();
		this.compactionMemory.setPartitionNumber(-1);
		// try to allocate maximum segment count
		int maxSegmentNumber = 0;
		for (InMemoryPartition<T> e : this.partitions) {
			if(e.getBlockCount() > maxSegmentNumber) {
				maxSegmentNumber = e.getBlockCount();
			}
		}
		this.compactionMemory.allocateSegments(maxSegmentNumber);
		if(this.compactionMemory.getBlockCount() > maxSegmentNumber) {
			this.compactionMemory.releaseSegments(maxSegmentNumber, availableMemory);
		}
	}
667081
boolean isCompactionRequired(SegmentProperties info) {
        long startOffset = getCompactionStartOffset(info);
        long lastIndexOffset = this.indexReader.getLastIndexedOffset(info);
        if (startOffset + this.connector.getMaxCompactionSize() >= lastIndexOffset) {
            // Either:
            // 1. Nothing was indexed
            // 2. Compaction has already reached the indexed limit.
            // 3. Not enough "uncompacted" data - at least this.maxCompactLength must be accumulated to trigger a compaction.
            return false;
        }

        long totalEntryCount = this.indexReader.getTotalEntryCount(info);
        long entryCount = this.indexReader.getEntryCount(info);
        long utilization = totalEntryCount == 0 ? 100 : MathHelpers.minMax(Math.round(100.0 * entryCount / totalEntryCount), 0, 100);
        long utilizationThreshold = (int) MathHelpers.minMax(this.indexReader.getCompactionUtilizationThreshold(info), 0, 100);
        return utilization < utilizationThreshold;
    }
725429
public boolean containsKey(Object key) {
        Entry tab[] = mTable;

        if (key != null) {
            int hash = key.hashCode();
            int index = (hash & 0x7FFFFFFF) % tab.length;
            for (Entry e = tab[index], prev = null; e != null; e = e.mNext) {
                if (e.getValue() == null) {
                    // Clean up after a cleared Reference.
                    mModCount++;
                    if (prev != null) {
                        prev.mNext = e.mNext;
                    }
                    else {
                        tab[index] = e.mNext;
                    }
                    mCount--;
                }
                else if (e.mHash == hash && key.equals(e.mKey)) {
                    return true;
                }
                else {
                    prev = e;
                }
            }
        }
        else {
            for (Entry e = tab[0], prev = null; e != null; e = e.mNext) {
                if (e.getValue() == null) {
                    // Clean up after a cleared Reference.
                    mModCount++;
                    if (prev != null) {
                        prev.mNext = e.mNext;
                    }
                    else {
                        tab[0] = e.mNext;
                    }
                    mCount--;
                }
                else if (e.mKey == null) {
                    return true;
                }
                else {
                    prev = e;
                }
            }
        }

        return false;
    }
1256541
public void containsEntry(@NullableDecl Object key, @NullableDecl Object value) {
    Entry<Object, Object> entry = Maps.immutableEntry(key, value);
    if (!actual().entrySet().contains(entry)) {
      List<Object> keyList = Lists.newArrayList(key);
      List<Object> valueList = Lists.newArrayList(value);
      if (hasMatchingToStringPair(actual().keySet(), keyList)) {
        failWithoutActual(
            simpleFact(
                lenientFormat(
                    "Not true that %s contains entry <%s (%s)>. However, it does contain keys "
                        + "<%s>.",
                    actualAsString(),
                    entry,
                    objectToTypeName(entry),
                    countDuplicatesAndAddTypeInfo(
                        retainMatchingToString(actual().keySet(), keyList /* itemsToCheck */)))));
      } else if (hasMatchingToStringPair(actual().values(), valueList)) {
        failWithoutActual(
            simpleFact(
                lenientFormat(
                    "Not true that %s contains entry <%s (%s)>. However, it does contain values "
                        + "<%s>.",
                    actualAsString(),
                    entry,
                    objectToTypeName(entry),
                    countDuplicatesAndAddTypeInfo(
                        retainMatchingToString(actual().values(), valueList /* itemsToCheck */)))));
      } else if (actual().containsKey(key)) {
        Object actualValue = actual().get(key);
        /*
         * In the case of a null expected or actual value, clarify that the key *is* present and
         * *is* expected to be present. That is, get() isn't returning null to indicate that the key
         * is missing, and the user isn't making an assertion that the key is missing.
         */
        StandardSubjectBuilder check = check("get(%s)", key);
        if (value == null || actualValue == null) {
          check = check.withMessage("key is present but with a different value");
        }
        // See the comment on IterableSubject's use of failEqualityCheckForEqualsWithoutDescription.
        check.that(actualValue).failEqualityCheckForEqualsWithoutDescription(value);
      } else if (actual().containsValue(value)) {
        Set<Object> keys = new LinkedHashSet<>();
        for (Entry<?, ?> actualEntry : actual().entrySet()) {
          if (Objects.equal(actualEntry.getValue(), value)) {
            keys.add(actualEntry.getKey());
          }
        }
        failWithoutActual(
            simpleFact(
                lenientFormat(
                    "Not true that %s contains entry <%s>. "
                        + "However, the following keys are mapped to <%s>: %s",
                    actualAsString(), entry, value, keys)));
      } else {
        failWithActual("expected to contain entry", entry);
      }
    }
  }
1164335
public void hasLastKey(@NullableDecl Object key) {
    if (actualAsNavigableMap().isEmpty()) {
      failWithActual("expected to have last key", key);
      return;
    }

    if (!Objects.equal(actualAsNavigableMap().lastKey(), key)) {
      if (actualAsNavigableMap().containsKey(key)) {
        failWithoutActual(
            simpleFact(
                lenientFormat(
                    "Not true that %s has last key <%s>. "
                        + "It does contain this key, but the last key is <%s>",
                    actualAsString(), key, actualAsNavigableMap().lastKey())));
        return;
      }
      failWithoutActual(
          simpleFact(
              lenientFormat(
                  "Not true that %s has last key <%s>. "
                      + "It does not contain this key, and the last key is <%s>",
                  actualAsString(), key, actualAsNavigableMap().lastKey())));
    }
  }
505419
public BinaryStore findBinaryStoreContainingKey( BinaryKey key ) {
        Iterator<Map.Entry<String, BinaryStore>> binaryStoreIterator = getNamedStoreIterator();

        while (binaryStoreIterator.hasNext()) {
            BinaryStore bs = binaryStoreIterator.next().getValue();
            if (bs.hasBinary(key)) {
                return bs;
            }
        }

        return null;
    }