Ejemplo n.º 1
0
size_t CompressInterface::varColor(size_t i) {
	foreach (const dai::BipartiteGraph::Neighbor tmpFac, _cfg.nbV(i)) {
		vector<size_t> hashAndPos(2);
		hashAndPos[0] = _facSigs[tmpFac];
		hashAndPos[1] = tmpFac.dual;
		_varInbox[i][tmpFac.iter] = hashVector(hashAndPos);

	}
	_varInbox[i][_varInbox[i].size() - 1] = _varSigs[i];
	sort(_varInbox[i].begin(), _varInbox[i].end());

	return hashVector(_varInbox[i]);
}
Ejemplo n.º 2
0
size_t CompressInterface::facColor(size_t i) {
	for (size_t j=0; j< _cfg.nbF(i).size(); j++) {
		_facInbox[i][j] = _varSigs[_cfg.nbF(i,j)];
	}
	_facInbox[i][_facInbox[i].size() - 1] = _facSigs[i];
	return hashVector(_facInbox[i]);
}
Ejemplo n.º 3
0
void
Coin::computeCommitments(std::vector<unsigned char>& a_pk)
{
    std::vector<unsigned char> k_internal;
    std::vector<unsigned char> k_internalhash_trunc(16);

    std::vector<unsigned char> k_internalhash_internal;
    concatenateVectors(a_pk, this->rho, k_internalhash_internal);

    std::vector<unsigned char> k_internalhash(k_size);
    hashVector(k_internalhash_internal, k_internalhash);

    copy(k_internalhash.begin(), k_internalhash.begin()+16, k_internalhash_trunc.begin());
    concatenateVectors(this->r, k_internalhash_trunc, k_internal);
    hashVector(k_internal, this->k);

    CoinCommitment com(this->coinValue, this->k);
    this->cm = com;
}
size_t AnyPositionCnfCompress::facColor(size_t i) {
	for (size_t j=0; j< _cfg.nbF(i).size(); j++) {
		_facInbox[i][j] = _varSigs[_cfg.nbF(i,_cfg.getSigma(i)[j])];
	}
	_facInbox[i][_facInbox[i].size() - 1] = _facSigs[i];

	double res = log(_cfg.factor(i).states() - _zeroStates[i]) /  log(2);
	size_t nrPosLiterals = size_t(res);
	sort(_facInbox[i].begin(), _facInbox[i].begin() + nrPosLiterals);
	sort(_facInbox[i].begin() + nrPosLiterals, _facInbox[i].end() - 1);

	return hashVector(_facInbox[i]);
}
Ejemplo n.º 5
0
SbBool
IfHasher::addIfNotThere(const float *newVector, int &index)
{
    ASSERT(curEntry < maxNum - 1);

    // Find the hash key
    uint32_t key = hashVector(newVector);

    // See if there already is a list of vectors with the same key
    void *list;
    if (vectorDict->find(key, list)) {

	// If so, look through the list for an exact match
	HashEntry *entry, *prevEntry = NULL;
	for (entry = (HashEntry *) list; entry != NULL; entry = entry->next) {

	    ASSERT(entry->index < curEntry);

	    // If the vectors are the same, re-use the old one and stop
	    if (sameVector(newVector, entry->index)) {
		index = entry->index;
		return FALSE;
	    }

	    prevEntry = entry;
	}

	// If there were no matches, add the new vector to the end of
	// the list
	ASSERT(prevEntry != NULL);
	entry = &entries[curEntry];
	entry->index = curEntry;
	entry->next = NULL;
	prevEntry->next = entry;
    }

    // If there were no entries in the dictionary, start one
    else {
	HashEntry *entry = &entries[curEntry];
	entry->index = curEntry;
	entry->next = NULL;
	vectorDict->enter(key, entry);
    }

    index = curEntry++;
    return TRUE;
}
Ejemplo n.º 6
0
void CompressInterface::initFacColors() {
	_facSigs = vector<Signature>(_cfg.nrFactors());
	vector<Real> potential;
	boost::hash<vector<Real> > hashVector;
	for (size_t i=0; i<_cfg.nrFactors(); i++) {
		bool allTrue = false;
		for (size_t j=0; j<i; j++)  {
			// muss set _facColorVec[i] properly
			if (_cfg.factor(i).states() != _cfg.factor(j).states()) {
				continue;
			}

			allTrue = true;
			for (size_t k=0; k<_cfg.factor(i).states(); k++) {
				if(_cfg.factor(i)[k] != _cfg.factor(j)[k]) {
					allTrue = false;
					break;
				}
			}

			if (allTrue) {
				_facSigs[i] = _facSigs[j];
				break;
			}
		}

		if (!allTrue) {
			potential.clear();
			potential.reserve(_cfg.factor(i).states());
			for (size_t k=0; k<_cfg.factor(i).states(); k++) {
				potential.push_back(_cfg.factor(i)[k]);
			}
			_facSigs[i] = hashVector(potential);
		}
		_facInbox.push_back(std::vector<size_t>(_cfg.nbF(i).size() + 1) );
	}
}