void ScrAddrFilter::checkForMerge()
{
   if (mergeFlag_ == true)
   {
      /***
      We're about to add a set of newly registered scrAddrs to the BDM's
      ScrAddrFilter map. Make sure they are scanned up to the last known
      top block first, then merge it in.
      ***/

      //create SAF to scan the addresses to merge
      std::shared_ptr<ScrAddrFilter> sca(copy());
      for (auto& scraddr : scrAddrDataForSideScan_.scrAddrsToMerge_)
         sca->scrAddrMap_.insert(scraddr);

      if (config().armoryDbType != ARMORY_DB_SUPER)
      {
         BinaryData lastScannedBlockHash = scrAddrDataForSideScan_.lastScannedBlkHash_;

         uint32_t topBlock = currentTopBlockHeight();
         uint32_t startBlock;

         //check last scanned blk hash against the blockchain      
         Blockchain& bc = blockchain();
         const BlockHeader& bh = bc.getHeaderByHash(lastScannedBlockHash);

         if (bh.isMainBranch())
         {
            //last scanned block is still on main branch
            startBlock = bh.getBlockHeight() + 1;
         }
         else
         {
            //last scanned block is off the main branch, undo till branch point
            const Blockchain::ReorganizationState state =
               bc.findReorgPointFromBlock(lastScannedBlockHash);
            ReorgUpdater reorg(state, &bc, lmdb_, config(), sca.get(), true);

            startBlock = state.reorgBranchPoint->getBlockHeight() + 1;
         }

         if (startBlock < topBlock)
            sca->applyBlockRangeToDB(startBlock, topBlock + 1, vector<string>());
      }

      //grab merge lock
      while (mergeLock_.fetch_or(1, memory_order_acquire));

      scrAddrMap_.insert(sca->scrAddrMap_.begin(), sca->scrAddrMap_.end());
      scrAddrDataForSideScan_.scrAddrsToMerge_.clear();

      mergeFlag_ = false;

      //release lock
      mergeLock_.store(0, memory_order_release);
   }
}
Beispiel #2
0
int search(int i) {
	int j, k;
	if (i == 1) {
		for (t[1] = 1; t[1] <= n; t[1] ++) {
			memset(inX, 0, sizeof(inX));
			memcpy(inY, initY, sizeof(initY));
			j = findIndex(bestTour.p, t[1]);
			shift(bestTour.p, j);
			t[2] = bestTour.p[2];
			if (inY[t[1]][t[2]]) continue;
			inX[t[1]][t[2]] = inX[t[2]][t[1]] = 1;
			if (search(i + 1)) return 1;
		}
	} else if (i == 2) {
		for (j = 2; j <= n; j ++) {
			cntTour = bestTour;
			t[3] = nearest[t[2]][j];
			if (t[3] == t[2] || t[3] == t[1] || t[3] == cntTour.p[3]) continue;
			if (dist[t[1]][t[2]] - dist[t[2]][t[3]] <= 0) continue;
			t[4] = cntTour.p[findIndex(cntTour.p, t[3]) - 1];
			if (inY[t[3]][t[4]]) continue;
			inY[t[2]][t[3]] = inY[t[3]][t[2]] = 1;
			inX[t[3]][t[4]] = inX[t[4]][t[3]] = 1;
			cntTour.length -= (dist[t[1]][t[2]] - dist[t[2]][t[3]]);
			reorg(cntTour.p, findIndex(cntTour.p, t[3]));
			if (cntTour.length - dist[t[3]][t[4]] + dist[t[4]][t[1]] < bestTour.length) {
				cntTour.length -= (dist[t[3]][t[4]] - dist[t[4]][t[1]]);
				bestTour = cntTour;
				return 1;
			}
			if (search(i + 1)) return 1;
			inY[t[2]][t[3]] = inY[t[3]][t[2]] = 0;
			inX[t[3]][t[4]] = inX[t[4]][t[3]] = 0;
		}
	} else if (i == 3) {
		Tour tourBuf = cntTour;
		for (k = 2; k <= n; k ++) {
			cntTour = tourBuf;
			t[5] = nearest[t[4]][k];
			if (t[5] == t[4] || t[5] == t[3] || t[5] == t[2] || t[5] == t[1] || t[5] == cntTour.p[3]) continue;
			if (dist[t[3]][t[4]] - dist[t[4]][t[5]] <= 0 || inX[t[4]][t[5]]) continue;
			inY[t[4]][t[5]] = inY[t[5]][t[4]] = 1;
			int lt = findIndex(cntTour.p, t[5]);
			cntTour.length -= (dist[t[3]][t[4]] - dist[t[4]][t[5]]);
			if (choose(3, lt)) return 1;
			inY[t[4]][t[5]] = inY[t[5]][t[4]] = 0;
		}
	}
	return 0;
}
Beispiel #3
0
bool Run(Node * node)
{
    const Tensor * input_tensor=node->GetInputTensor(0);
    Tensor * output_tensor=node->GetOutputTensor(0);
    const std::vector<int>& dims=input_tensor->GetShape().GetDim();

    float *input = (float *)get_tensor_mem(input_tensor);
    float *output = (float *)get_tensor_mem(output_tensor);
    Reorg *reorg_op = dynamic_cast<Reorg *>(node->GetOp());
    ReorgParam *param = reorg_op->GetParam();
    
   reorg(input, dims[3],dims[2],dims[1],dims[0], param->stride, output);

    return true;
}
Beispiel #4
0
int choose(int i, int lt) {
	if (i > n) return 0;
	// Choose xi(t[2i]).
	t[2*i] = cntTour.p[lt - 1];
	if (inY[t[2*i-1]][t[2*i]]) return 0;
	inX[t[2*i-1]][t[2*i]] = 1;
	inX[t[2*i]][t[2*i-1]] = 1;
	reorg(cntTour.p, lt);
	if (cntTour.length - dist[t[2*i-1]][t[2*i]] + dist[t[2*i]][t[1]] < bestTour.length) {
		cntTour.length -= (dist[t[2*i-1]][t[2*i]] - dist[t[2*i]][t[1]]); 
		bestTour = cntTour;
		return 1;
	}
	// Choose yi(t[2i+1]).
	int r, find = 0;
	for (r = 2; r <= n; r ++) {
		t[2*i+1] = nearest[t[2*i]][r];
		if (dist[t[2*i-1]][t[2*i]] - dist[t[2*i]][t[2*i+1]] > 0 && !inX[t[2*i]][t[2*i+1]]) {
			find = 1;
			break;
		}
	}
	if (!find) {
		inX[t[2*i-1]][t[2*i]] = 0;
		inX[t[2*i]][t[2*i-1]] = 0;
		return 0;
	}
	inY[t[2*i]][t[2*i+1]] = 1;
	inY[t[2*i+1]][t[2*i]] = 1;
	lt = findIndex(cntTour.p, t[2*i+1]);
	cntTour.length -= (dist[t[2*i-1]][t[2*i]] - dist[t[2*i]][t[2*i+1]]);
	if (choose(i + 1, lt)) return 1;
	else {
		inY[t[2*i]][t[2*i+1]] = 0;
		inY[t[2*i+1]][t[2*i]] = 0;
		return 0;
	}
}