Ejemplo n.º 1
0
DimensionBrowserDocumentation::DimensionBrowserDocumentation(PDatabase database, PDimension dimension, const string& message) :
	BrowserDocumentation(message)
{
	defineDatabase(database);
	defineDimension(dimension);

	ElementsType elements = dimension->getElements(PUser(), false);
	IdentifiersType elementIds;
	elementIds.reserve(elements.size());
	for (ElementsType::const_iterator it = elements.begin(); it != elements.end(); ++it) {
		elementIds.push_back((*it)->getIdentifier());
	}
	defineElements(dimension, elementIds.begin(), elementIds.end(), "@element");
}
Ejemplo n.º 2
0
uint32_t AggregationMap::storeDistributionSequence(
    const IdentifierType startId, const IdentifierType nextStartId,
    const IdentifiersType &targetIds, const vector<double> &targetWeights) {
  uint32_t distrMapIndex = uint32_t(-1);
  uint32_t distMapSequenceStart = uint32_t(-1);

  uint32_t newSize = (uint32_t) targetIds.size();
  uint32_t currentIndex = (uint32_t) distributionMap.size() - 1;
  // TODO: -jj- duplicities search in AggregationMap disabled because of performance problems
  for (vector<TargetSequence>::const_reverse_iterator dm = distributionMap
      .rbegin(); false && dm != distributionMap.rend(); ++dm, currentIndex--) {
    if (newSize == dm->length) {
      // compare content
      if (equal(targetIds.begin(), targetIds.end(),
                &targetIdBuffer[dm->startOffset])) {
        //uint32_t currentIndex = dm-distributionMap.rbegin();
        bool identicalWeights = false;
        if (targetWeights.empty() && weightBuffer.size() <= dm->startOffset) {
          // none of weights buffers exist - null == null
          identicalWeights = true;
        }
        if (weightBuffer.size()) {
          double *findEndIt = &weightBuffer[0]
              + min(dm->startOffset + dm->length,
                    (uint32_t) weightBuffer.size());
          if (!identicalWeights && targetWeights.empty()
              && std::find_if(&weightBuffer[dm->startOffset], findEndIt,
                              ISWeightNonDefault) == findEndIt) {
            // check if weightBuffer contains only 1.0 - null == default_weights
            identicalWeights = true;
          }
        }
        if (!identicalWeights && targetWeights.size()
            && weightBuffer.size() >= dm->startOffset + targetWeights.size()
            && equal(targetWeights.begin(), targetWeights.end(),
                     &weightBuffer[dm->startOffset])) {
          // both weight buffers exist - weights == weights
          identicalWeights = true;
        }
        if (identicalWeights) {
          distrMapIndex = currentIndex;
          //  LOG(INFO) << "duplicity saves: " << newSize*sizeof(targetIds[0]) << " B" << endl;
          break;
        }
      }
    }
  }

  //DLOG(INFO) << distrMapIndex << " " << distributionMap.size() << endl;
  if (distrMapIndex == uint32_t(-1)) {
    // copy sequence to buffers
    distMapSequenceStart = (uint32_t) targetIdBuffer.size();

    if (targetWeights.size()) {
      if (weightBuffer.size() != targetIdBuffer.size()) {
        weightBuffer.resize(targetIdBuffer.size(), 1.0);
      }
      copy(targetWeights.begin(), targetWeights.end(),
           std::back_insert_iterator<vector<double> >(weightBuffer));
    }
    copy(targetIds.begin(), targetIds.end(),
         std::back_insert_iterator<IdentifiersType>(targetIdBuffer));
    // write sequence start to distributionMap
    distrMapIndex = (uint32_t) (distributionMap.size());
    distributionMap.push_back(
        TargetSequence(distMapSequenceStart, (uint32_t) targetIds.size()));
  }
  if (source2TargetVector.empty()) {
    // update "map"
    if (source2TargetMap.empty()
        || source2TargetMap.back().distrMapIndex != distrMapIndex) {
      source2TargetMap.push_back(Source2TargetMapItem(startId, distrMapIndex));
      if (source2TargetMap.size() * sizeof(source2TargetMap[0])
          > (maxBaseId - minBaseId + 1) * sizeof(source2TargetVector[0])) {
        // convert "map" to vector
        source2TargetVector.resize(maxBaseId - minBaseId + 1);
        vector<Source2TargetMapItem>::const_iterator mapIt = source2TargetMap
            .begin();
        size_t seqBegin = mapIt->sourceRangeBegin - minBaseId;
        do {
          size_t seqEnd;
          uint32_t dmIndex = mapIt->distrMapIndex;
          if (++mapIt == source2TargetMap.end()) {
            seqEnd = maxBaseId - minBaseId + 1;
          } else {
            seqEnd = mapIt->sourceRangeBegin - minBaseId;
          }
          std::fill(&source2TargetVector[seqBegin],
                    &source2TargetVector[0] + seqEnd, dmIndex);
          seqBegin = seqEnd;
        } while (mapIt != source2TargetMap.end());
        source2TargetMap.clear();
      }
    }
  } else {
    // update vector
    size_t fillEnd = min(maxBaseId + 1, nextStartId);
    std::fill(&source2TargetVector[startId - minBaseId],
              &source2TargetVector[0] + fillEnd - minBaseId, distrMapIndex);
  }
  return distrMapIndex;
}