Exemplo n.º 1
0
void RAS_BucketManager::OrderBuckets(const MT_Transform& cameratrans, BucketList& buckets, vector<sortedmeshslot>& slots, bool alpha)
{
	BucketList::iterator bit;
	list<RAS_MeshSlot>::iterator mit;
	size_t size = 0, i = 0;

	/* Camera's near plane equation: pnorm.dot(point) + pval,
	 * but we leave out pval since it's constant anyway */
	const MT_Vector3 pnorm(cameratrans.getBasis()[2]);

	for (bit = buckets.begin(); bit != buckets.end(); ++bit)
	{
		SG_DList::iterator<RAS_MeshSlot> mit((*bit)->GetActiveMeshSlots());
		for(mit.begin(); !mit.end(); ++mit)
			size++;
	}

	slots.resize(size);

	for (bit = buckets.begin(); bit != buckets.end(); ++bit)
	{
		RAS_MaterialBucket* bucket = *bit;
		RAS_MeshSlot* ms;
		// remove the mesh slot form the list, it culls them automatically for next frame
		while((ms = bucket->GetNextActiveMeshSlot())) {
			slots[i++].set(ms, bucket, pnorm);
		}
	}
		
	if(alpha)
		sort(slots.begin(), slots.end(), backtofront());
	else
		sort(slots.begin(), slots.end(), fronttoback());
}
Exemplo n.º 2
0
BucketListMerger::BucketListMerger(const BucketList& newList,
                                   const BucketList& oldList,
                                   uint64_t timestamp)
    : _timestamp(timestamp)
{
    uint32_t i = 0;
    uint32_t j = 0;

    while (i < newList.size() || j < oldList.size()) {
        if (i >= newList.size()) {
            _removedEntries.push_back(oldList[j].first);
            j++;
        } else if (j >= oldList.size()) {
            _addedEntries.push_back(newList[i]);
            i++;
        } else if (newList[i].first.getId() > oldList[j].first.getId()) {
            _removedEntries.push_back(oldList[j].first);
            j++;
        } else if (newList[i].first.getId() < oldList[j].first.getId()) {
            _addedEntries.push_back(newList[i]);
            i++;
        } else {
            if (!(newList[i].second == oldList[j].second)) {
                _addedEntries.push_back(newList[i]);
            }
            i++; j++;
        }
    }
}
Exemplo n.º 3
0
void numberOfCCsMaxCC(Graph* g, int* numberOfCCs, int* maxCC) {
	List* intList = g->getAllIDs();
	int numberOfCC = 0;
	int numberOfNodes = 0;
	int maxNumCC = 0;
	LinearHashTable *hashTable = g->getHashTable();
	BucketList **bucketListTable = hashTable->getTable();
	for (int i = 0; i < hashTable->getCurrentBucketNo(); i++) {
		BucketList *bucketList = bucketListTable[i];
		BucketListItem *cur = (BucketListItem*) bucketList->getHead();
		while (cur != NULL) {
			Bucket *bucket = cur->getElement();
			for (int j = 0; j < bucket->getSize(); j++) {
				BucketItem *bi = bucket->getBucketItemByIndex(j);
				int startNodeId = bi->getNodeID();

				numberOfNodes = 0;
				bool skip = true;

				IntegerListItem* listNode = (IntegerListItem*) intList->getHead();
				while (listNode != NULL) {
					if (listNode->getInt() == startNodeId) {
						intList->deleteItem(listNode);
						numberOfCC++;
						numberOfNodes++;
						skip = false;
						break;
					}
					listNode = (IntegerListItem*) listNode->getNext();
				}

				if (!skip) {
					//reachNodeN from each node of the graph
					ResultSet *res = reachNodeN(startNodeId, g);
					Pair* pair;
					while (pair = res->next()) {
						IntegerListItem* searchListNode = (IntegerListItem*) intList->getHead();
						while (searchListNode != NULL) {
							if (searchListNode->getInt() == pair->getNodeId()) {
								intList->deleteItem(searchListNode);
								numberOfNodes++;
								break;
							}
							searchListNode = (IntegerListItem*) searchListNode->getNext();
						}

					}
					//delete res;		//free(): invalid next size (fast):
				}
				if (numberOfNodes > maxNumCC)
					maxNumCC = numberOfNodes;
			}
			cur = (BucketListItem*) cur->getNext();
		}
	}
	delete intList;

	*numberOfCCs = numberOfCC;
	*maxCC = maxNumCC;
}
Exemplo n.º 4
0
/**
 * Calculates the degree distribution of a graph and visualizes it using GNUPLOT.
 * Only considers out_degree.
 */
void degreeDistribution(Graph *g, bool checkFlag) {
	int nodeNo = g->getNodeNo();

	// Initialize array of N-1 elements to zeros ( holding the P(k)s, for k in (0,n-1) ).
	double totalCounters[nodeNo];
	for (int i = 0; i < nodeNo; i++)
		totalCounters[i] = 0;

	// Traverse HashTable and update all counters.
	LinearHashTable *hashTable = g->getHashTable();
	BucketList **bucketListTable = hashTable->getTable();
	for (int i = 0; i < hashTable->getCurrentBucketNo(); i++) {
		BucketList *bucketList = bucketListTable[i];
		BucketListItem *cur = (BucketListItem*) bucketList->getHead();
		while (cur) {
			Bucket *bucket = cur->getElement();
			// Count neighbors and update appropriate counter.
			for (int j = 0; j < bucket->getSize(); j++) {
				BucketItem *bi = bucket->getBucketItemByIndex(j);
				int count = bi->getEdgeList()->getSize();
				totalCounters[count]++;
			}

			cur = (BucketListItem*) cur->getNext();
		}
	}

	// Divide each counter by N.
	for (int i = 0; i < nodeNo; i++)
		totalCounters[i] = totalCounters[i] / nodeNo;

	if (checkFlag == true) {
		assert(int(totalCounters[0] * 10000) == 9898);
		assert(int(totalCounters[98] * 10000) == 101);
	}

	// Make data file.
	ofstream myFile;
	const char *filename = "graph_metrics/gnuplot/bin/data.txt";
	myFile.open(filename);
	if (myFile.fail()) {
		cout << "ERROR: Unable to open " << filename << endl;
		return;
	}

	myFile << "# K       P(K)" << endl;
	for (int i = 0; i < nodeNo; i++)
		myFile << i << "      " << 100 * totalCounters[i] << endl;
	myFile.close();

	// Run gnuplot to display graph.
#ifdef  __CYGWIN__
	system("cd graph_metrics/gnuplot/bin; ./gnuplot.exe degree.gnu");
#else
	system("cd graph_metrics/gnuplot/bin; wine gnuplot.exe degree.gnu");
#endif
}
Exemplo n.º 5
0
 void initializeBucketList
 (
     Int f                   // The index of the front to operate on
 )
 {
     // NOTE: tested by SPQR/Tcov, but not flagged as such in cov results
     BucketList *dlbl = (&bucketLists[f]);
     if(dlbl->useFlag) dlbl->Initialize();
 }
Exemplo n.º 6
0
BucketList* createBucketList(int nodeNo, int cellNo) {
	BucketList *bucketList = new BucketList(cellNo);
	Bucket *temp;
	for (int i = 0; i < nodeNo; i++) {
		temp = createBucket(cellNo, i * cellNo);
		for (int j = 0; j < temp->getSize(); j++)
			bucketList->insert(temp->getBucketItemByIndex(j));
	}
	return bucketList;
}
Exemplo n.º 7
0
// This code was copied from bulk data and used to remove entities
// from buckets.  In order to remove an entity, an appropriate entity
// must be found to copy into the hole.  This logic will find the
// appropriate bucket which has an entity to copy into the bucket.
void Transaction::remove_entity_from_bucket ( Entity &e , BucketList &buckets )
{
  Bucket *k = e.m_trans_bucket;
  unsigned i = e.m_trans_bucket_ord;

  Bucket * const first = k->m_key[ *k->m_key ] ? k->m_bucket : k ;
  Bucket * const last  = first->m_bucket ;

  // Only move if not the last entity being removed

  if ( last != k || k->m_size != i + 1 ) {

    // Not the same bucket or not the last entity

    // Copy last entity in last to ik slot i

    Entity * const entity = last->m_entities[ last->m_size - 1 ];

    k->m_entities[i]     = entity ;
    entity->m_trans_bucket     = k ;
    entity->m_trans_bucket_ord = i ;

  }

  --( last->m_size );

  if ( last->m_size != 0 ) {
    last->m_entities[ last->m_size ] = NULL ;
  }
  else {

    // The current 'last' bucket is to be deleted.
    // The previous 'last' bucket becomes the
    // new 'last' bucket in the family:

    std::vector<Bucket*>::iterator ik = lower_bound(buckets, last->m_key);

    ThrowRequireMsg( ik != buckets.end() && last == *ik,
        "Internal failure during removal of entity " << print_entity_key(e) );

    ik = buckets.erase( ik );

    if ( first != last ) { first->m_bucket = *--ik ; }

    Bucket::destroy_bucket( last );
  }

  e.m_trans_bucket = NULL;
}
Exemplo n.º 8
0
void print_bucket_list ( const BucketList &bl , std::ostream &os )
{
  BucketList::const_iterator  cur_bucket = bl.begin();
  while ( cur_bucket != bl.end() )
  {
    os << "Bucket key: ";
//This is bad code, no longer works. Re-visit this if/when the
//Transaction class is ever resurrected.
//    for ( unsigned i = 0 ; i <= (*cur_bucket)->m_key[0] ; i++ )
//      os << (*cur_bucket)->m_key[i] << " ";
//    os << "\n";
//    os << "Entities: ";
//    for ( unsigned i = 0 ; i != (*cur_bucket)->m_size ; i++ )
//      os << (*cur_bucket)->m_entities[i]->identifier() << " ";
//    os << "\n-------------------\n";
    cur_bucket++;
  }
}
Exemplo n.º 9
0
void
checkDBAgainstBuckets(medida::MetricsRegistry& metrics,
                      BucketManager& bucketManager, Database& db,
                      BucketList& bl)
{
    CLOG(INFO, "Bucket") << "CheckDB starting";
    auto execTimer =
        metrics.NewTimer({"bucket", "checkdb", "execute"}).TimeScope();

    // Step 1: Collect all buckets to merge.
    std::vector<std::shared_ptr<Bucket>> buckets;
    for (size_t i = 0; i < BucketList::kNumLevels; ++i)
    {
        CLOG(INFO, "Bucket") << "CheckDB collecting buckets from level " << i;
        auto& level = bl.getLevel(i);
        auto& next = level.getNext();
        if (next.isLive())
        {
            CLOG(INFO, "Bucket") << "CheckDB resolving future bucket on level "
                                 << i;
            buckets.push_back(next.resolve());
        }
        buckets.push_back(level.getCurr());
        buckets.push_back(level.getSnap());
    }

    if (buckets.empty())
    {
        CLOG(INFO, "Bucket") << "CheckDB found no buckets, returning";
        return;
    }

    // Step 2: merge all buckets into a single super-bucket.
    auto i = buckets.begin();
    assert(i != buckets.end());
    std::shared_ptr<Bucket> superBucket = *i;
    while (++i != buckets.end())
    {
        auto mergeTimer =
            metrics.NewTimer({"bucket", "checkdb", "merge"}).TimeScope();
        assert(superBucket);
        assert(*i);
        superBucket = Bucket::merge(bucketManager, *i, superBucket);
        assert(superBucket);
    }

    CLOG(INFO, "Bucket") << "CheckDB starting object comparison";

    // Step 3: scan the superbucket, checking each object against the DB and
    // counting objects along the way.
    uint64_t nAccounts = 0, nTrustLines = 0, nOffers = 0;
    {
        auto& meter = metrics.NewMeter({"bucket", "checkdb", "object-compare"},
                                       "comparison");
        auto compareTimer =
            metrics.NewTimer({"bucket", "checkdb", "compare"}).TimeScope();
        for (Bucket::InputIterator iter(superBucket); iter; ++iter)
        {
            meter.Mark();
            auto& e = *iter;
            if (e.type() == LIVEENTRY)
            {
                switch (e.liveEntry().data.type())
                {
                case ACCOUNT:
                    ++nAccounts;
                    break;
                case TRUSTLINE:
                    ++nTrustLines;
                    break;
                case OFFER:
                    ++nOffers;
                    break;
                }
                EntryFrame::checkAgainstDatabase(e.liveEntry(), db);
                if (meter.count() % 100 == 0)
                {
                    CLOG(INFO, "Bucket") << "CheckDB compared " << meter.count()
                                         << " objects";
                }
            }
        }
    }

    // Step 4: confirm size of datasets matches size of datasets in DB.
    soci::session& sess = db.getSession();
    compareSizes("account", AccountFrame::countObjects(sess), nAccounts);
    compareSizes("trustline", TrustFrame::countObjects(sess), nTrustLines);
    compareSizes("offer", OfferFrame::countObjects(sess), nOffers);
}