/* read a legend * MgetLegend reads a version 2 and 1 legend. * Version 1 legend are converted to version 2: the first * array entry holds an empty string in the description field. * returns * 0 if no legend is available or in case of an error, * nonzero otherwise */ int MgetLegend( MAP *m, /* Map handle */ CSF_LEGEND *l) /* array large enough to hold name and all entries, * the entries are sorted * struct CSF_LEGEND is typedef'ed in csfattr.h */ { CSF_ATTR_ID id = NrLegendEntries(m) < 0 ? ATTR_ID_LEGEND_V1 : ATTR_ID_LEGEND_V2; size_t size; CSF_FADDR pos = CsfGetAttrPosSize(m, id, &size); size_t i,nr,start = 0; if (pos == 0) return 0; fseek(m->fp, (long)pos, SEEK_SET); if (id == ATTR_ID_LEGEND_V1) { /* empty name */ l[0].nr = 0; l[0].descr[0] = '\0'; start = 1; /* don't read in name */ } nr = size/CSF_LEGEND_ENTRY_SIZE; for(i = start; i < nr+start; i++) { m->read(&(l[i].nr), sizeof(INT4), (size_t)1, m->fp); m->read(l[i].descr, sizeof(char), (size_t)CSF_LEGEND_DESCR_SIZE, m->fp); } SortEntries(l, nr+start); return 1; }
/* write a legend * MputLegend writes a (version 2) legend to a map replacing * the old one if existent. * See csfattr.h for the legend structure. * * returns * 0 in case of an error, * nonzero otherwise * * Merrno * NOACCESS * WRITE_ERROR */ int MputLegend( MAP *m, /* Map handle */ CSF_LEGEND *l, /* read-write, array with name and entries, the entries * are sorted before writing to the file. * Strings are padded with zeros. */ size_t nrEntries) /* number of array elements. That is name plus real legend entries */ { int i = NrLegendEntries(m); CSF_ATTR_ID id = i < 0 ? ATTR_ID_LEGEND_V1 : ATTR_ID_LEGEND_V2; if (i) if (! MdelAttribute(m, id)) return 0; SortEntries(l, nrEntries); if (CsfSeekAttrSpace(m, ATTR_ID_LEGEND_V2, (size_t)(nrEntries*CSF_LEGEND_ENTRY_SIZE)) == 0) return 0; for(i = 0; i < (int)nrEntries; i++) { if( m->write(&(l[i].nr), sizeof(INT4), (size_t)1, m->fp) != 1 || m->write( CsfStringPad(l[i].descr,(size_t)CSF_LEGEND_DESCR_SIZE), sizeof(char), (size_t)CSF_LEGEND_DESCR_SIZE, m->fp) != CSF_LEGEND_DESCR_SIZE ) { M_ERROR(WRITE_ERROR); return 0; } } return 1; }
/* SortEntries: use the id fields of the supplied list of nodes to build the required linTree or binTree */ static VQNode SortEntries(VQNode *list, short rootId) { VQNode newNode; newNode = FindVQNode(list,rootId); if (newNode == NULL) HError(6173,"SortEntries: cannot find node %d",rootId); if (newNode->lid != 0) newNode->left = SortEntries(list,newNode->lid); else newNode->left = NULL; if (newNode->rid != 0) newNode->right = SortEntries(list,newNode->rid); else newNode->right = NULL; return newNode; }
/* EXPORT->LoadVQTab: create a VQTable using defs in tabFN */ VQTable LoadVQTab(char *tabFN, short magic) { VQTable vq; Source src; short fmagic, numNodes, swidth[SMAX]; TreeType type; CovKind ck; VQNode n; int s,i; /* See if this VQ table already loaded */ if ((vq=FindVQTable(tabFN,magic)) != NULL) return vq; /* Load Definition Header Info and create table */ if(InitSource(tabFN,&src,NoFilter)<SUCCESS) HError(6110,"LoadVQTab: Can't open file %s", tabFN); fmagic = GetVal(&src,0,0,"magic number"); if (magic != 0 && magic != fmagic) HError(6170,"LoadVQTab: %s has magic=%d but reqd magic=%d", tabFN,fmagic,magic); type = (TreeType) GetVal(&src,linTree,binTree,"tree type"); ck = CKCheck((CovKind) GetVal(&src,DIAGC,NULLC,"cov kind")); numNodes = GetVal(&src,1,MAXVQNODES,"number of nodes"); swidth[0] = GetVal(&src,1,SMAX,"number of streams"); for (s=1; s<=swidth[0]; s++) swidth[s] = GetVal(&src,1,10000,"stream width"); vq = CreateVQTab(tabFN, fmagic, type, ck, swidth); /* Load Entries as unordered list */ for (i=1; i<=numNodes; i++){ s = GetVal(&src,1,SMAX,"stream index"); n = GetNode(&src,ck,swidth[s]); n->right = vq->tree[s]; vq->tree[s] = n; } vq->numNodes = numNodes; /* Sort Entries according to id numbers */ for (s=1; s<=swidth[0]; s++){ n = vq->tree[s]; vq->tree[s] = SortEntries(&n,1); } /* Close definition file and leave */ FClose(src.f,src.isPipe); return vq; }
SimpleProfilerViewer::SimpleProfilerViewer() : as::Sprite(), mLabels( NULL ), mEntries() { mLabels = new SimpleProfilerViewerEntry; mLabels->DoLabels(); addChild( mLabels ); mBuildNameSprite = as::LoadTextSprite( font_file ); mBuildNameSprite->SetColor( 1, 0, 0 ); mBuildNameSprite->SetText( mBuildName ); float x_position = 1024 - ( mBuildNameSprite->GetSize().x + 10.f); mBuildNameSprite->MoveTo( types::vector2( x_position, 768 - 20.f ) ); addChild( mBuildNameSprite ); Update(0.0f); SortEntries(); }
GiSTnode * MTnode::PickSplit () { int lDel, rDel; // number of entries to be deleted from each node int *lArray = new int[NumEntries()], *rArray = new int[NumEntries()]; // array of entries to be deleted from each node // promote the right node (possibly reassigning the left node); // the right node's page is copied from left node; // we'll delete from the nodes as appropriate after the splitting phase MTnode *rNode = PromotePart (); // now perform the split Split (rNode, lArray, rArray, &lDel, &rDel); // complexity: O(n) // given the deletion vectors, do bulk deletes DeleteBulk (lArray, lDel); rNode->DeleteBulk(rArray, rDel); // order the entries in both nodes SortEntries (); rNode->SortEntries(); delete []lArray; delete []rArray; return rNode; // return the right node }
void BroadPhase::GenerateCollisions() { int numPairs = bodies.size() * bodies.size(); memset(overlapMask, 0, sizeof(unsigned char) * maskByteSize); pairs.clear(); if (numPairs > maxPairs) ReallocateMask(); if (bodies.size() * 2 < entries[0].size()) { GenerateEntries(); } else if(newBodies.size() > 0) { UpdateEntries(); AddEntries(); //this way the newly added entries won't get updated since they will already be up to date } else { UpdateEntries(); } SortEntries(); indexActive.clear(); for (int i = 0; i < entries[first].size(); ++i) { if (entries[first][i].start) { indexActive.push_back(entries[first][i].index); for (int j = 0; j < indexActive.size() - 1; ++j) { SetMask(entries[first][i].index, indexActive[j], 0); } } else { for (int j = 0; j < indexActive.size(); ++j) { if (indexActive[j] == entries[first][i].index) indexActive.erase(indexActive.begin() + j); } } } for (int i = 0; i < entries[second].size(); ++i) { if (entries[second][i].start) { indexActive.push_back(entries[second][i].index); for (int j = 0; j < indexActive.size() - 1; ++j) { SetMask(entries[second][i].index, indexActive[j], 1); } } else { for (int j = 0; j < indexActive.size(); ++j) { if (indexActive[j] == entries[second][i].index) indexActive.erase(indexActive.begin() + j); } } } for (int i = 0; i < entries[third].size(); ++i) { if (entries[third][i].start) { indexActive.push_back(entries[third][i].index); for (int j = 0; j < indexActive.size() - 1; ++j) { if (CheckMask(entries[third][i].index, indexActive[j], 0) && CheckMask(entries[third][i].index, indexActive[j], 1)) { BroadPhasePair pair; pair.p1 = bodies[entries[third][i].index]; pair.p2 = bodies[indexActive[j]]; pair.p1->SetDebugColour(Vec4(1, 0, 0, 1)); pair.p2->SetDebugColour(Vec4(1, 0, 0, 1)); pairs.push_back(pair); } } } else { for (int j = 0; j < indexActive.size(); ++j) { if (indexActive[j] == entries[third][i].index) indexActive.erase(indexActive.begin() + j); } } } }