8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-24 00:03:03 +01:00

Make it compile with MSVC6

This commit is contained in:
alexpeshkoff 2003-01-06 17:35:21 +00:00
parent 4760bfc4df
commit f138cb4f22
3 changed files with 53 additions and 45 deletions

View File

@ -23,6 +23,7 @@
* Contributor(s): ______________________________________.
*/
#include "../../include/firebird.h"
#include "alloc.h"
#include <new>
@ -110,8 +111,8 @@ void MemoryPool::verify_pool() {
assert(blk->prev == prev); // Prev is correct ?
BlockInfo temp = {blk, blk->length};
bool foundTree = freeBlocks.locate(temp), foundPending = false;
for (PendingFreeBlock *temp = pendingFree; temp; temp = temp->next)
if (temp == (PendingFreeBlock *)((char*)blk+ALIGN(sizeof(MemoryBlock)))) {
for (PendingFreeBlock *tmp = pendingFree; tmp; tmp = tmp->next)
if (tmp == (PendingFreeBlock *)((char*)blk+ALIGN(sizeof(MemoryBlock)))) {
assert(!foundPending); // Block may be in pending list only one time
foundPending = true;
}

View File

@ -50,7 +50,8 @@ static void testTree() {
printf("Fill array with test data (%d items)...", TEST_ITEMS);
Vector<int, TEST_ITEMS> *v = new Vector<int, TEST_ITEMS>();
int n = 0;
for (int i=0;i<TEST_ITEMS;i++) {
int i;
for (i=0;i<TEST_ITEMS;i++) {
n = n * 45578 - 17651;
// Fill it with quasi-random values in range 0...TEST_ITEMS-1
v->add(((i+n) % TEST_ITEMS + TEST_ITEMS)/2);
@ -61,9 +62,9 @@ static void testTree() {
start();
BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
DefaultComparator<int>, 10, 10> tree10(NULL);
for (int i=0; i<TEST_ITEMS;i++)
for (i=0; i<TEST_ITEMS;i++)
tree10.add((*v)[i]);
for (int i=0; i<TEST_ITEMS;i++) {
for (i=0; i<TEST_ITEMS;i++) {
if (tree10.locate((*v)[i]))
tree10.fastRemove();
}
@ -72,9 +73,9 @@ static void testTree() {
start();
BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
DefaultComparator<int>, 50, 50> tree50(NULL);
for (int i=0; i<TEST_ITEMS;i++)
for (i=0; i<TEST_ITEMS;i++)
tree50.add((*v)[i]);
for (int i=0; i<TEST_ITEMS;i++) {
for (i=0; i<TEST_ITEMS;i++) {
if (tree50.locate((*v)[i]))
tree50.fastRemove();
}
@ -83,9 +84,9 @@ static void testTree() {
start();
BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
DefaultComparator<int>, 75, 75> tree75(NULL);
for (int i=0; i<TEST_ITEMS;i++)
for (i=0; i<TEST_ITEMS;i++)
tree75.add((*v)[i]);
for (int i=0; i<TEST_ITEMS;i++) {
for (i=0; i<TEST_ITEMS;i++) {
if (tree75.locate((*v)[i]))
tree75.fastRemove();
}
@ -94,9 +95,9 @@ static void testTree() {
start();
BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
DefaultComparator<int>, 100, 100> tree100(NULL);
for (int i=0; i<TEST_ITEMS;i++)
for (i=0; i<TEST_ITEMS;i++)
tree100.add((*v)[i]);
for (int i=0; i<TEST_ITEMS;i++) {
for (i=0; i<TEST_ITEMS;i++) {
if (tree100.locate((*v)[i]))
tree100.fastRemove();
}
@ -105,9 +106,9 @@ static void testTree() {
start();
BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
DefaultComparator<int>, 200, 200> tree200(NULL);
for (int i=0; i<TEST_ITEMS;i++)
for (i=0; i<TEST_ITEMS;i++)
tree200.add((*v)[i]);
for (int i=0; i<TEST_ITEMS;i++) {
for (i=0; i<TEST_ITEMS;i++) {
if (tree200.locate((*v)[i]))
tree200.fastRemove();
}
@ -116,9 +117,9 @@ static void testTree() {
start();
BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
DefaultComparator<int>, 250, 250> tree250(NULL);
for (int i=0; i<TEST_ITEMS;i++)
for (i=0; i<TEST_ITEMS;i++)
tree250.add((*v)[i]);
for (int i=0; i<TEST_ITEMS;i++) {
for (i=0; i<TEST_ITEMS;i++) {
if (tree250.locate((*v)[i]))
tree250.fastRemove();
}
@ -127,9 +128,9 @@ static void testTree() {
start();
BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
DefaultComparator<int>, 500, 500> tree500(NULL);
for (int i=0; i<TEST_ITEMS;i++)
for (i=0; i<TEST_ITEMS;i++)
tree500.add((*v)[i]);
for (int i=0; i<TEST_ITEMS;i++) {
for (i=0; i<TEST_ITEMS;i++) {
if (tree500.locate((*v)[i]))
tree500.fastRemove();
}
@ -137,9 +138,9 @@ static void testTree() {
std::set<int> stlTree;
start();
for (int i=0; i<TEST_ITEMS;i++)
for (i=0; i<TEST_ITEMS;i++)
stlTree.insert((*v)[i]);
for (int i=0; i<TEST_ITEMS;i++)
for (i=0; i<TEST_ITEMS;i++)
stlTree.erase((*v)[i]);
clock_t d = clock();
printf("Just a reference: add+remove %d elements from STL tree took %d milliseconds. \n",
@ -173,7 +174,8 @@ static void testAllocatorOverhead() {
bigItems(&allocator);
// Allocate small items
int n = 0;
for (int i=0;i<ALLOC_ITEMS;i++) {
int i;
for (i=0;i<ALLOC_ITEMS;i++) {
n = n * 47163 - 57412;
AllocItem temp = {n, (void*)i};
items.add(temp);
@ -185,7 +187,7 @@ static void testAllocatorOverhead() {
n++;
} while (n < ALLOC_ITEMS/2 && items.getNext());
// Allocate big items
for (int i=0;i<BIG_ITEMS;i++) {
for (i=0;i<BIG_ITEMS;i++) {
n = n * 47163 - 57412;
AllocItem temp = {n, (void*)i};
bigItems.add(temp);
@ -222,7 +224,7 @@ static void testAllocatorMemoryPool() {
n++;
} while (n < ALLOC_ITEMS/2 && items.getNext());
// Allocate big items
for (int i=0;i<BIG_ITEMS;i++) {
for (i=0;i<BIG_ITEMS;i++) {
n = n * 47163 - 57412;
AllocItem temp = {n, pool->alloc((n % BIG_SIZE + BIG_SIZE)/2+1)};
bigItems.add(temp);
@ -259,7 +261,7 @@ static void testAllocatorMalloc() {
n++;
} while (n < ALLOC_ITEMS/2 && items.getNext());
// Allocate big items
for (int i=0;i<BIG_ITEMS;i++) {
for (i=0;i<BIG_ITEMS;i++) {
n = n * 47163 - 57412;
AllocItem temp = {n, malloc((n % BIG_SIZE + BIG_SIZE)/2+1)};
bigItems.add(temp);
@ -284,7 +286,8 @@ static void testAllocatorOldPool() {
bigItems(&allocator);
// Allocate small items
int n = 0;
for (int i=0;i<ALLOC_ITEMS;i++) {
int i;
for (i=0;i<ALLOC_ITEMS;i++) {
n = n * 47163 - 57412;
AllocItem temp = {n, pool->allocate((n % MAX_ITEM_SIZE + MAX_ITEM_SIZE)/2+1,0)};
items.add(temp);
@ -296,7 +299,7 @@ static void testAllocatorOldPool() {
n++;
} while (n < ALLOC_ITEMS/2 && items.getNext());
// Allocate big items
for (int i=0;i<BIG_ITEMS;i++) {
for (i=0;i<BIG_ITEMS;i++) {
n = n * 47163 - 57412;
AllocItem temp = {n, pool->allocate((n % BIG_SIZE + BIG_SIZE)/2+1,0)};
bigItems.add(temp);

View File

@ -23,6 +23,7 @@
* Contributor(s): ______________________________________.
*/
#include "../../include/firebird.h"
#include "tree.h"
#include "alloc.h"
#include <stdio.h>
@ -32,12 +33,13 @@ using namespace Firebird;
void testVector() {
printf("Test Firebird::Vector: ");
Vector<int,100> v;
for (int i=0;i<100;i++)
int i;
for (i=0;i<100;i++)
v.add(i);
for (int i=0;i<50;i++)
for (i=0;i<50;i++)
v.remove(0);
bool passed = true;
for (int i=50;i<100;i++)
for (i=50;i<100;i++)
if (v[i-50] != i) passed = false;
printf(passed?"PASSED\n":"FAILED\n");
}
@ -45,12 +47,13 @@ void testVector() {
void testSortedVector() {
printf("Test Firebird::SortedVector: ");
SortedVector<int,100> v;
for (int i=0;i<100;i++)
int i;
for (i=0;i<100;i++)
v.add(99-i);
for (int i=0;i<50;i++)
for (i=0;i<50;i++)
v.remove(0);
bool passed = true;
for (int i=50;i<100;i++)
for (i=50;i<100;i++)
if (v[i-50] != i) passed = false;
printf(passed?"PASSED\n":"FAILED\n");
}
@ -66,13 +69,14 @@ struct Test {
};
void testBePlusTree() {
MallocAllocator temp;
printf("Test Firebird::BePlusTree\n");
MallocAllocator temp;
printf("Test Firebird::BePlusTree\n");
printf("Fill array with test data (%d items)...", TEST_ITEMS);
printf("Fill array with test data (%d items)...", TEST_ITEMS);
Vector<int, TEST_ITEMS> v;
int n = 0;
for (int i=0;i<TEST_ITEMS;i++) {
int i;
for (i=0;i<TEST_ITEMS;i++) {
n = n * 45578 - 17651;
// Fill it with quasi-random values in range 0...TEST_ITEMS-1
v.add(((i+n) % TEST_ITEMS + TEST_ITEMS)/2);
@ -85,7 +89,7 @@ void testBePlusTree() {
BePlusTree<Test, int, MallocAllocator, Test,
DefaultComparator<int>, 13, 13> tree2(&temp);
int cnt1 = 0, cnt2 = 0;
for (int i=0; i < v.getCount(); i++) {
for (i=0; i < v.getCount(); i++) {
if (tree1.locate(locEqual, v[i]))
tree1.current().count++;
else {
@ -112,7 +116,7 @@ void testBePlusTree() {
bool passed = true;
printf("Check that tree(2) contains test data: ");
for (int i=0; i< v.getCount(); i++) {
for (i=0; i< v.getCount(); i++) {
if(!tree1.locate(locEqual,v[i]))
passed = false;
}
@ -120,7 +124,7 @@ void testBePlusTree() {
passed = true;
printf("Check that tree(13) contains test data: ");
for (int i=0; i< v.getCount(); i++) {
for (i=0; i< v.getCount(); i++) {
if(!tree2.locate(locEqual,v[i]))
passed = false;
}
@ -173,7 +177,7 @@ void testBePlusTree() {
printf(" DONE\n");
printf("Check that tree(2) contains test data: ");
for (int i=0; i< v.getCount(); i++) {
for (i=0; i< v.getCount(); i++) {
if(!tree1.locate(locEqual,v[i]))
passed = false;
}
@ -181,7 +185,7 @@ void testBePlusTree() {
passed = true;
printf("Check that tree(13) contains test data: ");
for (int i=0; i < v.getCount(); i++) {
for (i=0; i < v.getCount(); i++) {
if(!tree2.locate(locEqual,v[i]))
passed = false;
}
@ -215,7 +219,7 @@ void testBePlusTree() {
passed = true;
printf("Remove the rest of data from the trees: ");
for (int i=0;i < v.getCount(); i++) {
for (i=0;i < v.getCount(); i++) {
if (!tree1.locate(locEqual, v[i]))
assert(false);
if (tree1.current().count > 1)
@ -241,7 +245,6 @@ void testBePlusTree() {
if (tree2.getLast())
passed = false;
printf(passed?"PASSED\n":"FAILED\n");
}
#define ALLOC_ITEMS 1000000
@ -266,8 +269,9 @@ void testAllocator() {
bigItems(&allocator);
printf("Allocate %d items: ", ALLOC_ITEMS);
int n = 0;
int i;
pool->verify_pool();
for (int i=0;i<ALLOC_ITEMS;i++) {
for (i=0;i<ALLOC_ITEMS;i++) {
n = n * 47163 - 57412;
AllocItem temp = {n, pool->alloc((n % MAX_ITEM_SIZE + MAX_ITEM_SIZE)/2+1)};
items.add(temp);
@ -287,7 +291,7 @@ void testAllocator() {
printf("Allocate %d big items: ", BIG_ITEMS);
n = 0;
pool->verify_pool();
for (int i=0;i<BIG_ITEMS;i++) {
for (i=0;i<BIG_ITEMS;i++) {
n = n * 47163 - 57412;
AllocItem temp = {n, pool->alloc((n % BIG_SIZE + BIG_SIZE)/2+1)};
bigItems.add(temp);
@ -313,7 +317,7 @@ void testAllocator() {
MemoryPool::deletePool(pool);
}
int main() {
void main() {
testVector();
testSortedVector();
testBePlusTree();