Example #1
0
IOperand *TOperand<T>::doMod(eOperandType type, const std::string &left, const std::string &right) const
{
    T l_value;
    T r_value;
    std::istringstream l_ss(left);
    std::istringstream r_ss(right);

    l_ss >> l_value;
    r_ss >> r_value;

    try
    {
        if (r_value == 0)
            throw Exception("Floating exception (Modulo by 0)");
    } catch (Exception ex)
    {
        std::cerr << ex.what() << std::endl;
        exit(0x53);
    }
    if (TRAIT::is_float<T>::value || TRAIT::is_double<T>::value)
    {
        checkOverflow(fmod(l_value, r_value));
        checkUnderflow(fmod(l_value, r_value));
        return new TOperand<T>(type, fmod(l_value, r_value));
    }
    else
    {
        checkOverflow((l_value - ((l_value / r_value) * r_value)));
        checkUnderflow((l_value - ((l_value / r_value) * r_value)));
        return new TOperand<T>(type, (l_value - ((l_value / r_value) * r_value)));
    }
}
Example #2
0
IOperand *TOperand<int8>::doMul(eOperandType type, const std::string &left, const std::string &right) const
{
    int l_value;
    int r_value;
    std::istringstream l_ss(left);
    std::istringstream r_ss(right);

    l_ss >> l_value;
    r_ss >> r_value;
    checkOverflow(l_value * r_value);
    checkUnderflow(l_value * r_value);

    return new TOperand<int8>(type, (l_value * r_value));
}
Example #3
0
IOperand *TOperand<T>::doLess(eOperandType type, const std::string &left, const std::string &right) const
{
    T l_value;
    T r_value;
    std::istringstream l_ss(left);
    std::istringstream r_ss(right);

    l_ss >> l_value;
    r_ss >> r_value;
    checkOverflow(l_value - r_value);
    checkUnderflow(l_value - r_value);

    return new TOperand<T>(type, (l_value - r_value));
}
Example #4
0
IOperand *TOperand<int8>::doMod(eOperandType type, const std::string &left, const std::string &right) const
{
    int l_value;
    int r_value;
    std::istringstream l_ss(left);
    std::istringstream r_ss(right);

    l_ss >> l_value;
    r_ss >> r_value;

    try
    {
        if (r_value == 0)
            throw Exception("Floating exception (Modulo by 0)");
    } catch (Exception ex)
    {
        std::cerr << ex.what() << std::endl;
        exit(0x53);
    }
    checkOverflow((l_value % r_value));
    checkUnderflow((l_value % r_value));

    return new TOperand<int8>(type, (l_value % r_value));
}
Example #5
0
IOperand *TOperand<T>::doDiv(eOperandType type, const std::string &left, const std::string &right) const
{
    T l_value;
    T r_value;
    std::istringstream l_ss(left);
    std::istringstream r_ss(right);

    l_ss >> l_value;
    r_ss >> r_value;

    try
    {
        if (r_value == 0)
            throw Exception("Floating exception (Divide by 0)");
    } catch (Exception ex)
    {
        std::cerr << ex.what() << std::endl;
        exit(0x52);
    }
    checkOverflow(l_value / r_value);
    checkUnderflow(l_value / r_value);

    return new TOperand<T>(type, (l_value / r_value));
}
// delete the specified key from the Btree
RC deleteKey(BTreeHandle *tree, Value *key) {

	Btree* leaf      = NULL;
	// get the desired leaf
	leaf = find_leaf(tree, key);

	// get the left node
	Btree* childLeft = NULL;
	childLeft = leaf->prev;

	// get the tree stastistics data
	Btree_stat *info = NULL;
	info = tree->mgmtData;

	if (leaf != NULL) {

		if (childLeft == NULL) {

			// no child
			// delete the entry and adjust the tree if needed
			delete_entry(tree, leaf, key);

			// done
			return RC_OK;
		}

		if (key->v.intV == leaf->keys[0]) {

			// the key exists in this leaf node
			// delete it
			delete_entry(tree, leaf, key);

			// check if there is underflow in the node capacity
			if (leaf->num_keys == 0) {

				// merge with the left sibling
				childLeft->next = leaf->next;

				// check if we need to propagate this change up the tree
				delete_parent_nodes_inital(info, leaf, key);

				// done
				return RC_OK;
			}

			// update the prent node
			updateFirst(leaf, key);

			return RC_OK;

		} else {

			delete_entry(tree, leaf, key);

			if (leaf) {

				// see of there is underflow
				if (checkUnderflow(info, leaf)) {

					// if yes, merge with left sibling
					if (childLeft) {

						// check the number of keys even after splitting
						if (childLeft->num_keys > splitNode(info->order)
						&&  childLeft->num_keys != info->order) {

							// we need to redistribute the keys
							// to balance out
							redistribute(info, childLeft, leaf);

						} else {
							// just merge
							merge_nodes(info, childLeft, leaf);
						}
					}
				}
			}

			return RC_OK;
		}
	}

	// all ok
	return RC_OK;
}