Initial size handling

This commit is contained in:
IlyaShurupov 2024-10-10 11:17:03 +03:00 committed by Ilya Shurupov
parent 9f9dcd5882
commit 0b73f8037b
28 changed files with 543 additions and 135 deletions

View file

@ -17,7 +17,7 @@ Item buff[size];
int main() {
AvlTree<AvlNumericKey<alni>, alni> tree;
for (auto i : Range(size)) {
for (auto i : IterRange(size)) {
buff[i].data = i;
}

View file

@ -9,7 +9,7 @@ SUITE(Buffer) {
TEST(Simple1) {
Buffer<TestClass, TestAllocator> buff;
CHECK(buff.size() == 0);
for (auto i : Range(size * 10)) {
for (auto i : IterRange(size * 10)) {
buff.append(TestClass(i));
}
CHECK(buff.size() == size * 10);
@ -21,7 +21,7 @@ SUITE(Buffer) {
TEST(Simple2) {
Buffer<TestClass, TestAllocator> buff(size);
CHECK(buff.size() == size);
for (auto i : Range(size * 10))
for (auto i : IterRange(size * 10))
buff.append(TestClass(i));
CHECK(buff.size() == size + size * 10);
while (buff.size())

View file

@ -99,7 +99,7 @@ SUITE(IntervalTree) {
};
// initialize
for (auto i : Range<ualni>(NUM_TEST_INTERVALS)) {
for (auto i : IterRange<ualni>(NUM_TEST_INTERVALS)) {
auto interval = Interval();
interval.random(SPAN);
@ -114,7 +114,7 @@ SUITE(IntervalTree) {
test();
// remove some
for (auto i : Range<ualni>(NUM_TEST_INTERVALS / 2)) {
for (auto i : IterRange<ualni>(NUM_TEST_INTERVALS / 2)) {
auto idx = ualni(randomFloat() * (alnf) pool.size());
pool[idx].ignore = true;
intervalTree.remove({ pool[idx].start, pool[idx].end });
@ -139,18 +139,18 @@ SUITE(IntervalTree) {
Buffer<Interval> testIntervals;
auto WOBBLE = SPAN * 0;
for (auto i : Range<ualni>(NUM_TEST_INTERVALS)) {
for (auto i : IterRange<ualni>(NUM_TEST_INTERVALS)) {
auto interval = Interval();
interval.randomSized(SPAN, SCALE, WOBBLE);
intervalTree.insert({ interval.start, interval.end }, i);
// WOBBLE -= 1.f;
}
for (auto i : Range(0))
for (auto i : IterRange(0))
intervalTree.insert({ (halnf) i * 0.01f, SPAN }, 0);
WOBBLE = 0;
for (auto i : Range<ualni>(NUM_CHECKS)) {
for (auto i : IterRange<ualni>(NUM_CHECKS)) {
auto interval = Interval();
interval.randomSized(SPAN, SCALE, WOBBLE);
testIntervals.append(interval);
@ -200,7 +200,7 @@ SUITE(IntervalTree) {
};
Buffer<Stat> stats;
for (auto i : Range(2, 5)) {
for (auto i : IterRange(2, 5)) {
Stat stat = test(pow(10, i), 100);
stats.append(stat);
}

View file

@ -8,26 +8,26 @@ SUITE(HashTable) {
TEST(SimpleReference) {
tp::Map<tp::ualni, TestClass, TestAllocator> map;
for (auto i : Range(1000, 100000)) {
for (auto i : IterRange(1000, 100000)) {
map.put(i, TestClass(i));
}
for (auto i : Range(1000, 100000)) {
for (auto i : IterRange(1000, 100000)) {
CHECK(map.presents(i));
CHECK_EQUAL((tp::ualni) map.get(i).getVal(), (tp::ualni) i);
}
for (auto i : Range(1000, 100000)) {
for (auto i : IterRange(1000, 100000)) {
map.put(i, TestClass(i));
}
for (auto i : Range(1000, 2000)) {
for (auto i : IterRange(1000, 2000)) {
CHECK(map.presents(i));
map.remove(i);
CHECK(!map.presents(i));
}
for (auto i : Range(2000, 100000)) {
for (auto i : IterRange(2000, 100000)) {
CHECK(map.presents(i));
CHECK_EQUAL((tp::ualni) map.get(i).getVal(), (tp::ualni) i);
}
@ -42,29 +42,29 @@ SUITE(HashTable) {
TEST(SimplePointer) {
tp::Map<tp::ualni, TestClass*, TestAllocator> map;
for (auto i : Range(1000)) {
for (auto i : IterRange(1000)) {
map.put(i, new TestClass(i));
}
for (auto i : Range(1000)) {
for (auto i : IterRange(1000)) {
CHECK(map.presents(i));
CHECK_EQUAL((tp::ualni) map.get(i)->getVal(), (tp::ualni) i);
}
for (auto i : Range(1000)) {
for (auto i : IterRange(1000)) {
auto del = map.get(i);
map.put(i, new TestClass(i));
delete del;
}
for (auto i : Range(900, 1000)) {
for (auto i : IterRange(900, 1000)) {
CHECK(map.presents(i));
delete map.get(i);
map.remove(i);
CHECK(!map.presents(i));
}
for (auto i : Range(900)) {
for (auto i : IterRange(900)) {
CHECK(map.presents(i));
CHECK_EQUAL((tp::ualni) map.get(i)->getVal(), (tp::ualni) i);
}
@ -80,7 +80,7 @@ SUITE(HashTable) {
TEST(Copy) {
tp::Map<tp::ualni, TestClass, TestAllocator> map;
for (auto i : Range(10)) {
for (auto i : IterRange(10)) {
map.put(i, TestClass(i));
}
@ -95,7 +95,7 @@ SUITE(HashTable) {
TEST(SaveLoad) {
tp::Map<tp::ualni, TestClass, TestAllocator> map;
for (auto i : Range(10)) {
for (auto i : IterRange(10)) {
map.put(i, TestClass(i));
}
@ -114,7 +114,7 @@ SUITE(HashTable) {
CHECK(map.size() == 10);
for (auto i : Range(10)) {
for (auto i : IterRange(10)) {
CHECK(map.presents(i));
CHECK_EQUAL(map.get(i).getVal(), i);
}

View file

@ -37,7 +37,7 @@ SUITE(AvlTree) {
Item buff[size];
for (auto i : Range(size)) {
for (auto i : IterRange(size)) {
buff[i].data.setVal(i);
}