F2D* resizeArray(F2D* array, int omin) 
{
	F2D* prev = NULL;
	F2D* current = array;
	int o;
    if(omin<0)
    {
        for(o=1; o>=-omin; o--)
        {
			prev = current;
            current = doubleSize(current);
			fFreeHandle(prev);
        }
    }
    if(omin>0)
    {
        for(o=1; o<= omin; o++)
		{
			prev = current;
            current = halveSize(current);
			fFreeHandle(prev);
		}
    }
	return current;
}
Exemple #2
0
void insertToTable(int prefix, int c, Table **stringTable, int PRUNE)
{
	char ENCODE_OR_DECODE[25] = "encode";
	int index = ++(*stringTable)->last;
	if(index >= (*stringTable)->size) { //next code inserted into index that does not exist
		--(*stringTable)->last;
		if((*stringTable)->nBits == (*stringTable)->MAXBITS) { //time to prune (*stringTable)->size == 1<<(*stringTable)->MAXBITS
			if(PRUNE == -1){
				return;
			} else {
				prune(stringTable, PRUNE, ENCODE_OR_DECODE);
				return;
			}
		} else { //time to double stringTable size and increase nBits
			Table * temp = *stringTable;
			(*stringTable)->nBits++;
			(*stringTable)->size *= 2;
			if((*stringTable)->size > 1<<(*stringTable)->MAXBITS) {
				fprintf(stderr, "INSERTTABLE: DOUBLED SIZE: stringTable->size = %d, stringTable->nbits = %d , index = %d, maxbits = %d\n", temp->size, temp->nBits, index, temp->MAXBITS );
				exit(EXIT_FAILURE);
			}
			doubleSize(*stringTable, (*stringTable)->size);
			// fprintf(stderr, "nbits: %d, size: %d, index: %d", temp->nBits, temp->size, index);
		}
	}
	Pair *pair = (*stringTable)->table[index];
	pair->prefix = prefix;
	pair->c = c;

	linkHash(prefix, c, index, (*stringTable));
}
void push(dynamicStack *S, int data)
{
    if( isFull(S) )
    {
        doubleSize(S);
    }

    S->elementsArray[++S->top] = data;
}
Exemple #4
0
void addPair(char* key, int value, hashTable* hTable) {
	hTable->loadFactor = insertPair(key, value, hTable->table, hTable->tableSize, hTable->loadFactor);

	if(hTable->loadFactor > hTable->maxLoad) {
		hTable->table = doubleSize(hTable->table, hTable->tableSize, hTable->loadFactor);
		hTable->loadFactor = hTable->loadFactor / 2;
		hTable->tableSize = hTable->tableSize * 2;
	}
}
Exemple #5
0
            //Adds the new byte at the end of the FlexBit.
            void addLast(byte b)
            {
                //If current size is >= totalSize then double totalSize.
                if (size + startIndex >= totalSize - 1)
                {
                    doubleSize();
                }

                container[startIndex + size] = b;
                ++size;
            }
Exemple #6
0
void ArrayList::addToEnd(Data toAdd) {
    clock_t start = clock();
    if (currSize < capacity) {
        theArray[currSize] = new Data(toAdd);
    }
    else {
        doubleSize();
        theArray[currSize] = new Data(toAdd);
    }
    currSize++;
    ticks += clock() - start;

}
Exemple #7
0
//Inserts a data element into a bag
void Bag::bag_insert(ULLI data) {

	//Confirm bag has enough space to insert
	while (size >= exp2(scale)) {
		doubleSize();
	}

	//Convert data to Pennant
	Pennant* toInsert = new Pennant(data);
	int k = 0;
	//Adding one pennant is analogous to adding by 1 on structure
	while (penArray[k] != nullptr) {
		toInsert->pen_union(penArray[k]);
		penArray[k++] = nullptr;
	}
	penArray[k] = toInsert;
	size += 1;
}
Exemple #8
0
//Unions two bag structures (NOTE: bags have to have same scale)
Bag* Bag::bag_union(Bag* other) {
	Pennant* carry = nullptr;
	int bitcode;

	//unioning bags is analogous to adding the pennants

	if (other == nullptr) return this; //handle identity case

	//allows new object in the case the union is too large
	while (size + other->size >= exp(scale)) {
		doubleSize();	
	}

	for (int k = 0; k < scale + 1; ++k) {
		bitcode = 0;
		bitcode += (carry != nullptr) * 4;
		bitcode += (other->penArray[k] != nullptr) * 2;
		bitcode += (penArray[k] != nullptr);

		switch(bitcode) {
		case 0: //both pennants null, no carry
			carry = nullptr;
			penArray[k] = nullptr;
			break;
		case 1: //other pennant null, no carry
			carry = nullptr;
			//penArray[k] doesn't change
			break;
		case 2: //local pennant null, no carry
			carry = nullptr;
			penArray[k] = other->penArray[k];
			break;
		case 3: //both pennant non-null, no carry
			carry = penArray[k]->pen_union(other->penArray[k]);
			penArray[k] = nullptr;
			break;
		case 4: //both pennants null with carry
			penArray[k] = carry;
			carry = nullptr;
			break;
		case 5: //other pennant null with carry
			carry = penArray[k]->pen_union(carry);
			penArray[k] = nullptr;
			break;
		case 6: //local pennant null with carry
			carry = other->penArray[k]->pen_union(carry);
			penArray[k] = nullptr;
			break;
		case 7: //no pennant null
			carry = other->penArray[k]->pen_union(carry);
			//penArray[k] doesn't change
			break;
		default:
			cout << "Error in case statement in Bag::bag_union()" << endl;
			throw 1; //should not be reached
		}
	}
	//DEBUG
	if (carry != nullptr) {
		cout << "Error: overflow in Bag::bag_union()" << endl;
		throw 1;
	}
	size += other->size;
	return this;
}