예제 #1
0
// Add entries to a HashMap until either we get an OOM, or the table has been
// resized a few times.
static bool GrowUntilResize() {
  IntMap m;

  // Add entries until we've resized the table four times.
  size_t lastCapacity = m.capacity();
  size_t resizes = 0;
  uint32_t key = 0;
  while (resizes < 4) {
    auto p = m.lookupForAdd(key);
    if (!p && !m.add(p, key, 0)) {
      return false;  // OOM'd in lookupForAdd() or add()
    }

    size_t capacity = m.capacity();
    if (capacity != lastCapacity) {
      resizes++;
      lastCapacity = capacity;
    }
    key++;
  }

  return true;
}
예제 #2
0
// Add entries to a HashMap using lookupWithDefault until either we get an OOM,
// or the table has been resized a few times.
static bool
LookupWithDefaultUntilResize() {
    IntMap m;

    if (!m.init())
        return false;

    // Add entries until we've resized the table four times.
    size_t lastCapacity = m.capacity();
    size_t resizes = 0;
    uint32_t key = 0;
    while (resizes < 4) {
        if (!m.lookupWithDefault(key++, 0))
            return false;

        size_t capacity = m.capacity();
        if (capacity != lastCapacity) {
            resizes++;
            lastCapacity = capacity;
        }
    }

    return true;
}