// src/objects/ordered-hash-table.cc

template <class Derived, int entrysize>
template <template <typename> typename HandleType>
	requires(std::is_convertible_v<HandleType<Derived>, DirectHandle<Derived>>)
HandleType<Derived>::MaybeType
OrderedHashTable<Derived, entrysize>::EnsureCapacityForAdding(
    Isolate* isolate, HandleType<Derived> table) {
  DCHECK(!table->IsObsolete());

  int nof = table->NumberOfElements(); // 실제 요소수
  int nod = table->NumberOfDeletedElements(); // 삭제된 요소 수
  int capacity = table->Capacity(); // 현재 테이블의 총 용량
  
  // 용량을 추가할 필요가 없음. 기존의 테이블을 ealry return
  if ((nof + nod) < capacity) return table;

  int new_capacity;
  if (capacity == 0) {
    // step from empty to minimum proper size
    // 비어 있는 테이블은 최소 크기로 초기화 함
    new_capacity = kInitialCapacity;
  }
 // 삭제된 엔트리가 너무 많으면 용량을 키울 필요가 없음. 리해시만으로도 삭제된 공간을 재사용할 수 있음
  else if (nod >= (capacity >> 1)) {
    // Don't need to grow if we can simply clear out deleted entries instead.
    // Note that we can't compact in place, though, so we always allocate
    // a new table.
    new_capacity = capacity;
  }
  // 용량 2배로 증가
  else {
    new_capacity = capacity << 1;
  }

  return Derived::Rehash(isolate, table, new_capacity);
}