private void splitAndRearrangeEntries(HashMapSegmentLayout segment) throws IOException {
    int hashSuffixDepth = header.globalHashSuffixDepth();
    int segmentHashDepth = segment.hashSuffixDepth();
    if (hashSuffixDepth == segmentHashDepth) {
      doubleSegmentsTable();
    }
    assert header.globalHashSuffixDepth() > segment.hashSuffixDepth()
      : "globalHashSuffixDepth(=" + header.globalHashSuffixDepth() + ") " +
        "must be > segment.hashSuffixDepth(=" + segment.hashSuffixDepth() + ")";

    Pair<HashMapSegmentLayout, HashMapSegmentLayout> splitSegments = split(segment);
    HashMapSegmentLayout oldSegment = splitSegments.first;
    HashMapSegmentLayout newSegment = splitSegments.second;

    //redirect each 2nd oldSegment reference to the newSegment:
    int[] newSegmentSlotIndexes = slotIndexesForSegment(
      newSegment.hashSuffix(),
      newSegment.hashSuffixDepth(),
      header.globalHashSuffixDepth()
    );
    for (int segmentSlotIndex : newSegmentSlotIndexes) {
      int segmentIndex = header.segmentIndex(segmentSlotIndex);
      assert segmentIndex == oldSegment.segmentIndex()
        : "segment[" + segmentSlotIndex + "].segmentIndex(=" + segmentIndex + ") but it must be " + oldSegment.segmentIndex();

      header.updateSegmentIndex(segmentSlotIndex, newSegment.segmentIndex());
    }
  }
private void splitAndRearrangeEntries(HashMapSegmentLayout segment)