Exemplo n.º 1
0
 void WriteResult::_check(bool throwSoftErrors) {
     if (hasWriteErrors())
         throw OperationException(writeErrors().back());
     if (throwSoftErrors && hasWriteConcernErrors()) {
         throw OperationException(writeConcernErrors().front());
     }
 }
CTreeNodeUnaryOperation::CTreeNodeUnaryOperation(UnaryOperation t, AbstractTreeNode *l){
	if(!left)
		throw OperationException("Ошибка построения узла. Строка содержит ошибку.");
	left = l;
	right = NULL;
	type = t;
}
Exemplo n.º 3
0
    BSONObj CommandWriter::_send(
        BSONObjBuilder* command,
        const WriteConcern* writeConcern,
        const StringData& ns
    ) {
        command->append("writeConcern", writeConcern->obj());

        BSONObj result;
        bool commandWorked = _client->runCommand(nsToDatabase(ns), command->obj(), result);

        if (!commandWorked) throw OperationException(result);

        return result;
    }
double CTreeNodeUnaryOperation::get_value(const vector<double> &x){
	if(!left)
		throw OperationException("Ошибка построения узла. Строка содержит ошибку.");
	switch(type){
		case Cos:				
			return cos(left->get_value(x));
		case Sin:
			return sin(left->get_value(x));
		case Exp:
			return exp(left->get_value(x));
		case Tan:
			return tan(left->get_value(x));
		break;
	}
}
    BSONObj WireProtocolWriter::_send(Operations opCode, const BufBuilder& builder, const WriteConcern* wc, const StringData& ns) {
        Message request;
        request.setData(opCode, builder.buf(), builder.len());
        _client->say(request);

        BSONObj result;

        if (wc->requiresConfirmation()) {
            BSONObjBuilder bob;
            bob.append("getlasterror", true);
            bob.appendElements(wc->obj());
            _client->runCommand(nsToDatabase(ns), bob.obj(), result);

            if (!result["err"].isNull()) {
                throw OperationException(result);
            }
        }

        return result;
    }
Exemplo n.º 6
0
node_idx ArrayOperation::apply(const level k, const node_idx p[], const unsigned int size)
{
	node_idx r = 0;
	if (k > m_forest->top_level())
		throw OperationException("Level out of range.\n");

	if (k == 0) {
		return base_case(p, size);
	}

	r = m_cache[k]->hit(k, p, size);
	if (r >= 0) {
		//If the node has been deleted, restore it before returning.
		if (m_forest->FDDL_NODE(k, r).deleted())
			r = m_forest->CheckIn(k, r);
		return r;
	}

	r = m_forest->NewNode(k);

	int maxsize = 0;
	for (unsigned int i=0; i < size; ++i) {
		Node* node = &m_forest->FDDL_NODE(k,i);
		if (node->m_size > maxsize)
			maxsize = node->m_size;
	}

	Node* nodes[size];

	for (unsigned int i=0; i < size; ++i) {
		nodes[i] = &m_forest->FDDL_NODE(k,p[i]);
	}

	arc_idx index[size];
	for (unsigned int i=0; i < size; ++i) {
		index[i] = 0;
	}
	bool done = false;

	while (!done) {
		done = true;
		arc_idx idx[size];	
		node_idx val[size];
		for (unsigned int i=0; i < size; ++i) {
			if (index[i] < nodes[i]->size() && nodes[i]->sparse()){
				idx[i] = m_forest->SPARSE_INDEX(k, nodes[i], index[i]);
				val[i] = m_forest->SPARSE_ARC(k, nodes[i], index[i]);
				++index[i];
				done = false;
			}
			else if (index[i] < nodes[i]->size()){
				idx[i] = index[i];
				val[i] = m_forest->FULL_ARC(k, nodes[i], index[i]);
				++index[i];
				done = false;
			}
			else {
				idx[i] = -1;
				val[i] = 0;
			}
		}
		arc_idx mindx = 0;
		for (unsigned int i=1; i < size; ++i) {
			if (val[i] >= 0 && idx[i] < idx[mindx]) {
				mindx = i;
			}
		}
		for (unsigned int i=1; i < size; ++i) {
			if (idx[i] != idx[mindx])
				val[i] = 0;
		}
		if (idx[mindx] != 0) 
			m_forest->SetArc(k, r, idx[mindx], apply(k-1, val, size));
	}
	r = m_forest->CheckIn(k, r);
	m_cache[k]->add(k, p, size, r);
	return r;
}