Example #1
0
static bool SlowRekey(IntMap* m) {
  IntMap tmp;

  for (auto iter = m->iter(); !iter.done(); iter.next()) {
    if (NewKeyFunction::shouldBeRemoved(iter.get().key())) {
      continue;
    }
    uint32_t hi = NewKeyFunction::rekey(iter.get().key());
    if (tmp.has(hi)) {
      return false;
    }
    if (!tmp.putNew(hi, iter.get().value())) {
      return false;
    }
  }

  m->clear();
  for (auto iter = tmp.iter(); !iter.done(); iter.next()) {
    if (!m->putNew(iter.get().key(), iter.get().value())) {
      return false;
    }
  }

  return true;
}
Example #2
0
static bool MapsAreEqual(IntMap& am, IntMap& bm) {
  bool equal = true;
  if (am.count() != bm.count()) {
    equal = false;
    fprintf(stderr, "A.count() == %u and B.count() == %u\n", am.count(),
            bm.count());
  }
  for (auto iter = am.iter(); !iter.done(); iter.next()) {
    if (!bm.has(iter.get().key())) {
      equal = false;
      fprintf(stderr, "B does not have %x which is in A\n", iter.get().key());
    }
  }
  for (auto iter = bm.iter(); !iter.done(); iter.next()) {
    if (!am.has(iter.get().key())) {
      equal = false;
      fprintf(stderr, "A does not have %x which is in B\n", iter.get().key());
    }
  }
  return equal;
}
Example #3
0
static bool
MapsAreEqual(IntMap& am, IntMap& bm)
{
    bool equal = true;
    if (am.count() != bm.count()) {
        equal = false;
        fprintf(stderr, "A.count() == %u and B.count() == %u\n", am.count(), bm.count());
    }
    for (IntMap::Range r = am.all(); !r.empty(); r.popFront()) {
        if (!bm.has(r.front().key())) {
            equal = false;
            fprintf(stderr, "B does not have %x which is in A\n", r.front().key());
        }
    }
    for (IntMap::Range r = bm.all(); !r.empty(); r.popFront()) {
        if (!am.has(r.front().key())) {
            equal = false;
            fprintf(stderr, "A does not have %x which is in B\n", r.front().key());
        }
    }
    return equal;
}
Example #4
0
static bool
SlowRekey(IntMap *m) {
    IntMap tmp;
    tmp.init();

    for (IntMap::Range r = m->all(); !r.empty(); r.popFront()) {
        if (NewKeyFunction::shouldBeRemoved(r.front().key))
            continue;
        uint32_t hi = NewKeyFunction::rekey(r.front().key);
        if (tmp.has(hi))
            return false;
        tmp.putNew(hi, r.front().value);
    }

    m->clear();
    for (IntMap::Range r = tmp.all(); !r.empty(); r.popFront()) {
        m->putNew(r.front().key, r.front().value);
    }

    return true;
}