/// Reassign the integer values to the strings.  Upon successful completion
/// of this function, the integer values assigned to the strings will be in
/// ascending order.  In other word, string values that are lexigraphically
/// smaller will have smaller integer representations.
///
/// The argument to this function carrys the permutation information needed
/// to turn the previous integer assignments into the new ones.  If the
/// previous assignment was k, the new assignement will be o2n[k].  Note
/// that the name o2n is shorthand for old-to-new.
void ibis::dictionary::sort(ibis::array_t<uint32_t> &o2n) {
    const size_t nelm = raw_.size();
    ibis::array_t<uint32_t> n2o(nelm);
    for (size_t j = 0; j < nelm; ++ j)
        n2o[j] = j;
#if DEBUG+0 > 2 || _DEBUG+0 > 2
    {
        ibis::util::logger lg;
        lg() << "DEBUG -- dictionary::sort starts with\n\t";
        for (MYMAP::const_iterator it = key_.begin(); it != key_.end(); ++ it)
            lg() << '"' << it->first << '"' << "(" << it->second << ") ";
    }
#endif
    ibis::util::sortStrings(raw_, n2o);
    o2n.resize(nelm);
    for (size_t j = 0; j < nelm; ++ j)
        o2n[n2o[j]] = j;
    for (MYMAP::iterator it = key_.begin(); it != key_.end(); ++ it)
        it->second = o2n[it->second];
#if DEBUG+0 > 2 || _DEBUG+0 > 2
    {
        ibis::util::logger lg;
        lg() << "DEBUG -- dictionary::sort ends with";
        for (MYMAP::const_iterator it = key_.begin(); it != key_.end(); ++ it)
            lg() << "\n\t\"" << it->first << '"' << "(" << it->second << ": "
                 << raw_[it->second] << ") ";
        lg() << "\n\to2n(" << o2n.size() << "):";
        for (size_t j = 1; j < nelm; ++ j)
            lg() << "\n\to2n[" << j << "] = " << o2n[j] << ": " << raw_[o2n[j]];
    }
#endif
} // ibis::dictionary::sort
Exemple #2
0
/// Reassign the integer values to the strings.  Upon successful completion
/// of this function, the integer values assigned to the strings will be in
/// ascending order.  In other word, string values that are lexigraphically
/// smaller will have smaller integer representations.
///
/// The argument to this function carrys the permutation information needed
/// to turn the previous integer assignments into the new ones.  If the
/// previous assignment was k, the new assignement will be o2n[k].  Note
/// that the name o2n is shorthand for old-to-new.
void ibis::dictionary::sort(ibis::array_t<uint32_t> &o2n) {
    const size_t nelm = code_.size();
    o2n.resize(nelm+1);
    o2n[0] = 0;  // 0 is always mapped to 0
    for (uint32_t j = 0; j < nelm; ++ j) {
	raw_[j+1] = key_[j];
	o2n[code_[j]] = j+1;
	code_[j] = j+1;
    }
} // ibis::dictionary::sort
Exemple #3
0
int FQ_Variable::getPointValues(ibis::array_t<E>& arr,
                                const std::vector<uint64_t>& coords) const {
    if (! isValid("FQ_Variable::getPointValues")) return 0;

    std::string evt = "FQ_Variable::getPointValues";
    if (ibis::gVerbose > 1) {
        std::ostringstream oss;
        oss << '(' << (thePart->name() ? thePart->name() : "?") << '.'
            << name() << ", " << ibis::TYPESTRING[(int)m_type]
            << ", coords[" << coords.size() << "])";
        evt += oss.str();
    }
    arr.resize(coords.size() / varInfo.getNDims());

    LOGGER(ibis::gVerbose > 0)
        << "FQ_Variable::getPointValues the arr size is " << arr.size() ;

    bool ret;
    if (useAll) {
    	ret = dataFile.getPointData(varInfo.getPath(), coords,
				    static_cast<void*>(arr.begin()));
    } else {
	// convert to absolute coords based on space info.
	std::vector<uint64_t> absCoords;
	absCoords.resize(coords.size());
	std::vector<uint64_t> offsets = varSpace.getOffsets();
	std::vector<uint64_t> counts = varSpace.getCounts();
	std::vector<uint64_t> strides = varSpace.getStrides();
	unsigned int idx = 0;
	for (unsigned int i=0; i<arr.size(); i++) {
	    for (unsigned int j=0; j<varInfo.getNDims(); j++) {
		absCoords[idx] = coords[idx]* strides[j] + offsets[j];
		idx++;
	    }
	}
    	ret = dataFile.getPointData(varInfo.getPath(), absCoords,
				    static_cast<void*>(arr.begin()));
    }
    if (ret)
        return arr.size();
    else
        return -1;
} // FQ_Variable::getPointValues
/// Produce an array that maps the integers in old dictionary to the new
/// one.  The incoming dictionary represents the old dictionary, this
/// dictionary represents the new one.
///
/// Upon successful completion of this fuction, the array o2n will have
/// (old.size()+1) number of elements, where the new value for the old code
/// i is stored as o2n[i].
int ibis::dictionary::morph(const ibis::dictionary &old,
                            ibis::array_t<uint32_t> &o2n) const {
    const uint32_t nold = old.key_.size();
    const uint32_t nnew = key_.size();
    if (nold > nnew) {
        LOGGER(ibis::gVerbose > 0)
            << "Warning -- dictionary::morph can not proceed because the "
            "new dictioanry is smaller than the old one";
        return -1;
    }

    o2n.resize(nold+1);
    o2n[0] = 0;
    if (nold == 0) return 0;

    for (uint32_t j0 = 1; j0 < old.raw_.size(); ++ j0)
        o2n[j0] = operator[](raw_[j0]);
    return nold;
} // ibis::dictioniary::morph
Exemple #5
0
/// Produce an array that mapps the integers in old dictionary to the new
/// one.  The incoming dictionary represents the old dictionary, this
/// dictionary represents the new one.
///
/// Upon successful completion of this fuction, the array o2n will have
/// (old.size()+1) number of elements, where the new value for the old code
/// i is stored as o2n[i].
int ibis::dictionary::morph(const ibis::dictionary &old,
			    ibis::array_t<uint32_t> &o2n) const {
    const uint32_t nold = old.key_.size();
    const uint32_t nnew = key_.size();
    if (nold > nnew) {
	LOGGER(ibis::gVerbose > 0)
	    << "Warning -- dictionary::morph can not proceed because the "
	    "new dictioanry is smaller than the old one";
	return -1;
    }

    o2n.resize(nold+1);
    o2n[0] = 0;
    if (nold == 0) return 0;

    uint32_t j1 = 0, j0 = 0;
    while (j0 < nold && j1 < nnew) {
	int cmp = strcmp(key_[j1], old.key_[j0]);
	if (cmp < 0) {
	    ++ j1;
	}
	else if (cmp == 0) {
	    o2n[old.code_[j0]] = code_[j1];
	    ++ j0;
	    ++ j1;
	}
	else {
	    LOGGER(ibis::gVerbose > 0)
		<< "Warning -- dictionary::morph can not find \""
		<< old.key_[j0] << "\" in the new dictionary";
	    return -2;
	}
    }
    if (j0 < nold) {
	LOGGER(ibis::gVerbose > 0)
	    << "Warning -- dictionary::morph exhausted the new dictionary "
	    "entries but only found " << j0 << " out of " << nold
	    << " entr" << (nold>1?"ies":"y") << " from the old one";
	return -3;
    }
    return j0;
} // ibis::dictioniary::morph