STDMETHODIMP MailPropertyMap::get_Item(BSTR index, BSTR* pVal) { try { if(0 == index) throw Workshare::ArgumentNullException(_T("index"), _T("The property index may not be null.")); if(0 == pVal) throw Workshare::ArgumentNullException(_T("pVal"), _T("The return buffer for the property value must be valid.")); _bstr_t indexName(index); _wcslwr(indexName); *pVal = SysAllocString(m_map[indexName.GetBSTR()].c_str()); return S_OK; } catch(Workshare::Exception const& e) { return AtlReportError(__uuidof(this), e.Message, __uuidof(IMailPropertyMap), e.ErrorCode); } catch(...) { return AtlReportError(__uuidof(this), L"Unexpected Error", __uuidof(IMailPropertyMap), ProcessUnhandledException()); } }
STDMETHODIMP MailPropertyMap::put_Item(BSTR index, BSTR newVal) { try { if(0 == index) throw Workshare::ArgumentNullException(_T("index"), _T("The property index may not be null.")); _bstr_t indexName(index); _wcslwr(indexName); if(0 != newVal) m_map[indexName.GetBSTR()] = newVal; else m_map[indexName.GetBSTR()] = L""; return S_OK; } catch(Workshare::Exception const& e) { return AtlReportError(__uuidof(this),e.Message, __uuidof(IMailPropertyMap), e.ErrorCode); } catch(...) { return AtlReportError(__uuidof(this),L"Unexpected Error", __uuidof(IMailPropertyMap), ProcessUnhandledException()); } }
static int voteUnvotedSIVN( VRR* it, const StoredIndexVoteNode* votes, NameIndexEntry* cur ) { int i; int unvoted = 1; for ( i = 0; i < votes->numVotes; i++ ) { if ( votes->vote[i].index == cur->index ) { unvoted = 0; break; } } if ( unvoted ) { // All names not voted assumed to rate -0, lose to names with >= 0 ratings and beat < 0 ratings. int j; if ( debug ) { printf("unvoted %d \"%s\"\n", cur->index, indexName( it->ni, cur->index ) ); } for ( j = 0; j < votes->numVotes; j++ ) { if ( votes->vote[j].rating >= 0 ) { incxy( votes->vote[j].index, cur->index ); } else { incxy( cur->index, votes->vote[j].index ); } } } i = 0; if ( cur->lt != NULL ) { i |= voteUnvotedSIVN( it, votes, cur->lt ); } if ( cur->gt != NULL ) { i |= voteUnvotedSIVN( it, votes, cur->gt ); } return i; }
/* delete this index. does NOT clean up the system catalog (system.indexes or system.namespaces) -- only NamespaceIndex. */ void IndexDetails::kill_idx() { string ns = indexNamespace(); // e.g. foo.coll.$ts_1 try { string pns = parentNS(); // note we need a copy, as parentNS() won't work after the drop() below // clean up parent namespace index cache NamespaceDetailsTransient::get_w( pns.c_str() ).deletedIndex(); string name = indexName(); /* important to catch exception here so we can finish cleanup below. */ try { dropNS(ns.c_str()); } catch(DBException& ) { log(2) << "IndexDetails::kill(): couldn't drop ns " << ns << endl; } head.setInvalid(); info.setInvalid(); // clean up in system.indexes. we do this last on purpose. int n = removeFromSysIndexes(pns.c_str(), name.c_str()); wassert( n == 1 ); } catch ( DBException &e ) { log() << "exception in kill_idx: " << e << ", ns: " << ns << endl; } }
void IndexDetails::kill_idx() { const string ns = indexNamespace(); const string parentns = parentNS(); close(); storage::db_remove(ns); // Removing this index's ns from the system.indexes/namespaces catalog. removeNamespaceFromCatalog(ns); if (nsToCollectionSubstring(parentns) != "system.indexes") { removeFromSysIndexes(parentns, indexName()); } }
void VRR_makeWinners( VRR* it, int* defeatCount ) { int i; if ( it->winners != NULL ) { free( it->winners ); it->winners = NULL; } it->winners = (NameVote*)malloc( sizeof(NameVote)*it->numc ); assert( it->winners != NULL ); for ( i = 0; i < it->numc; i++ ) { it->winners[i].name = indexName( it->ni, i ); it->winners[i].rating = 0.0 - defeatCount[i]; } sortNameVotes( it->winners, it->numc ); }
void Stack::Init(){ title = name; name = indexName(name); frame = NULL; can = NULL; leg = new TLegend(0.7, 0.8, 1, 1); leg -> SetFillColor(0); leg -> SetLineColor(0); _displayLegend = true; gStyle->SetOptStat(0); labelSizeX = 0; labelSizeY = 0; verbose = 0; }
void Stack::draw1D(){ if( debug > 0 ) std::cout << "Stack::draw1D()" << std::endl; int nHisto = vec.size(); int Ngraph = vecGraph.size(); if( frame == NULL ){ ComputeLimits(); float *binX = normalBinning(100, limitsX.first, limitsX.second); float *binY; if(limitsY.first >= 0 && (limitsY.second - limitsY.first) > 1e3){ if(limitsY.first == 0) limitsY.first = 0.8; binY = logarithmicBinning(100, limitsY.first, limitsY.second + topMarginFactor * (limitsY.second - limitsY.first) ); } else binY = normalBinning(100, limitsY.first, limitsY.second + topMarginFactor * (limitsY.second - limitsY.first) ); frame = new TH2F( indexName("frame").c_str(), title.c_str(),100, binX, 100, binY); frame -> GetXaxis() -> SetTitle( titleX.c_str() ); frame -> GetYaxis() -> SetTitle( titleY.c_str() ); } can -> cd( ); frame -> Draw(); for(int i = 0;i<nHisto;i++){ vec[i] -> SetLineColor( getColor(i) ); vec[i] -> SetLineWidth(2); if( nHisto == 1 ) vec[i] -> SetFillColor(18); drawingOption[ vec[i] ] += "same"; vec[i] -> Draw( drawingOption[ vec[i] ].c_str() ); } // Add all graphs on the plot for(int i = nHisto;i<Ngraph+nHisto;i++) drawGraph( vecGraph[i-nHisto], i ); int Nlines = vecLine.size(); for(int i = nHisto + Ngraph;i<Ngraph+nHisto+Nlines;i++){ drawLine( vecLine[i-(nHisto+Ngraph)] ); vecLine[i-(nHisto+Ngraph)] -> SetLineColor( getColor(i) ); } int NTF1 = vecTF1.size(); for(int i = 0; i<NTF1;i++){ vecTF1[i] -> SetLineColor( getColor(i+Ngraph+nHisto+Nlines) ); vecTF1[i] -> Draw("same"); } }
void Stack::setFrame( float infX, float supX, float infY, float supY ){ if(frame) delete frame; if( supX < infX ){ std::cerr << "WARNING: borne sup X cannot be smaller than borne inf X" << std::endl; return; } if( supY < infY ){ std::cerr << "WARNING: borne sup Y cannot be smaller than borne inf Y" << std::endl; return; } std::string theName = indexName("frame"); frame = new TH2F(theName.c_str(), title.c_str(),10000, infX, supX, 10000, infY, supY); frame -> GetXaxis() -> SetTitle( titleX.c_str() ); frame -> GetYaxis() -> SetTitle( titleY.c_str() ); }
static int enumerateNChoseKNameIndexHelper( NameIndex* in, int numChoices, int votePos, int* slatei, int depth, int depthLimit, int start, struct strbuf* b, NameIndex* out ) { while ( start < numChoices ) { slatei[depth] = start; if ( depth == depthLimit ) { int j; int seats = depthLimit + 1; // this is true. depthLimit passed to optimize more frequent test above. int newnamelen = 0; int newindex; // Add up the rating for everything in the in-vote that is in this slate permutation. for ( j = 0; j < seats; ++j ) { const char* jname = indexName(in, slatei[j]); int jlen = strlen(jname); if ((newnamelen + jlen + 2) > b->len) { b->len = newnamelen + jlen + 512; b->buf = (char*)realloc(b->buf, b->len); assert(b->buf); } strcpy(b->buf + newnamelen, jname); newnamelen += jlen; b->buf[newnamelen] = ','; newnamelen++; } newnamelen--; b->buf[newnamelen] = '\0'; newindex = nameIndex( out, b->buf ); assert(newindex == votePos); votePos++; } else { votePos = enumerateNChoseKNameIndexHelper( in, numChoices, votePos, slatei, depth + 1, depthLimit, start + 1, b, out ); } start++; } return votePos; }
// Constructor for the Index class. The arguments passed in are // 'name' -- file name of the relation // 'offset', 'length', 'type' -- describing the attribute indexed // 'unique' -- flag for enforcing uniquess of the entries Index::Index(const string& name, const int offset, const int length, const Datatype type, const int unique, Status& status) { Page* pagePtr; file = 0; // For this assignment turn off hash indices on strings if (type == STRING ) { status = NOCHARIDX; return; } if(name.empty()) { status = BADFILE; return; } if (offset < 0 || length < 1) { status = BADINDEXPARM; return; } if (type != STRING && type != INTEGER && type != DOUBLE){ status = BADINDEXPARM; return; } if ((type == INTEGER && length != sizeof(int)) || (type == DOUBLE && length != sizeof(double))) { status = BADINDEXPARM; return; } curBuc = NULL; recSize = length + sizeof(RID); // size of the index entry numSlots = (PAGESIZE - 2*sizeof(short)) / recSize; // # entries on a page status = OK; // get name of the index file by concatenating relation name and // the offset of the attribute ostringstream outputString; outputString << name << '.' << offset << ends; string indexName(outputString.str()); // The constructor runs in two cases. In the first case, an index // doesn't exist as detected by db.openFile. The relation file // should be scanned and each tuple is inserted to the index. In // the second case, an index already exists. Only the headerPage // needs to read in and pinned down in the buffer pool. file = 0; status = db.openFile(indexName, file); if (status != OK) { // index doesn't exit. Create it status = db.createFile(indexName); if (status != OK) return; // open the file status = db.openFile(indexName, file); if (status != OK) return; // allocate and initialize the header page status = bufMgr->allocPage(file, headerPageNo, (Page*&)headerPage); if (status != OK) return; strcpy(headerPage->fileName, name.c_str()); headerPage->offset = offset; headerPage->length = length; headerPage->type = type; headerPage->depth = 0; headerPage->unique = unique; dirSize = 1; // allocate and initialize the first bucket pointed by dir[0] int pageNo; Bucket* bucket; status = bufMgr->allocPage(file, pageNo, (Page*&)bucket); if (status != OK) return; bucket->depth = 0; bucket->slotCnt = 0; headerPage->dir[0] = pageNo; status = bufMgr->unPinPage(file, pageNo, true); if (status != OK) return; // build index by scanning the relation file and inserting every // tuple HeapFileScan heapFileScan(name, offset, length, type, NULL, EQ, status); if (status != OK) return; Record rec; RID rid; while(1) { status = heapFileScan.scanNext(rid); if (status == FILEEOF) { status = OK; break; } status = heapFileScan.getRecord(rid, rec); if (status != OK) return; status = insertEntry((char *)rec.data + offset, rid); if (status != OK) return; } } else { // file already exists. get header page into the buffer pool status = file->getFirstPage(headerPageNo); if (status != OK) { cerr << "fetch of first page failed\n"; return; } status = bufMgr->readPage(file, headerPageNo, pagePtr); if (status != OK) { cerr << "read of first page failed\n"; return; } headerPage = (iHeaderPage*) pagePtr; dirSize = (int)pow(2.0, headerPage->depth); } }
const char *Operand::string() const { static char string[256]; if(isVoid(type)) { return 0; } else if(isImm(type)) { if(reference) { return reference; } else { if(value <= 127 && value >= -128) { snprintf(string, 255, "0x%0.2X", value & 0xFF); } else if(value <= 32767 && value -32768) { snprintf(string, 255, "0x%0.4X", value & 0xFFFF); } else { snprintf(string, 255, "0x%0.8X", value); } } } else if(isReg(type)) { return regName(); } else if(isMem(type)) { switch(type) { case OPERAND_MEM8: snprintf(string, 255, "byte ptr ["); break; case OPERAND_MEM16: snprintf(string, 255, "word ptr ["); break; case OPERAND_MEM32: snprintf(string, 255, "dword ptr ["); break; case OPERAND_MEM64: snprintf(string, 255, "qword ptr ["); break; case OPERAND_MEM128: snprintf(string, 255, "xmmword ptr ["); break; case OPERAND_MEM: default: snprintf(string, 255, "byte ptr ["); } if(baseReg != Encoding::REG_UNKNOWN) { snprintf(string, 255, "%s%s", string, regName()); if(indexReg != Encoding::REG_UNKNOWN) { snprintf(string, 255, "%s+", string); } } if(indexReg != Encoding::REG_UNKNOWN) { snprintf(string, 255, "%s%s", string, indexName()); } switch(scale) { case 0: case 1: break; case 2: snprintf(string, 255, "%s*2", string); break; case 4: snprintf(string, 255, "%s*4", string); break; case 8: snprintf(string, 255, "%s*8", string); break; default: throw INTERNAL_ERROR; } if(displacement) { if(baseReg != Encoding::REG_UNKNOWN || indexReg != Encoding::REG_UNKNOWN) { snprintf(string, 255, "%s+", string); } if(reference) { snprintf(string, 255, "%s%s", string, reference); } else { if(displacement <= 32767 && displacement >= -32768) { snprintf(string, 255, "%s%d", string, displacement); } else { snprintf(string, 255, "%s0x%0.8X", string, displacement); } } } snprintf(string, 255, "%s]", string); } else { throw INTERNAL_ERROR; } return strlwr(string); }
// http://wiki.electorama.com/wiki/Ranked_Pairs int VRR_RankedPairs( VRR* it, int winnersLength, NameVote** winnersP, int* defeatCount ) { pair* ranks; int numc = it->numc; int i, j; int x = 0; ranks = (pair*)malloc( sizeof(pair) * ((numc * numc) / 2) ); for ( i = 0; i < numc; ++i ) { for ( j = i + 1; j < numc; ++j ) { int ij, ji; ij = xy(i,j); ji = xy(j,i); if ( ij > ji ) { ranks[x].i = i; ranks[x].j = j; ranks[x].Vij = ij; ranks[x].Vji = ji; ranks[x].active = 1; x++; } else if ( ji > ij ) { ranks[x].i = j; ranks[x].j = i; ranks[x].Vij = ji; ranks[x].Vji = ij; ranks[x].active = 1; x++; } else { // tie policy? } } } qsort(ranks, x, sizeof(pair), pair_cmp_qsort); if ( verbose ) { for ( i = 0; i < x; ++i ) { fprintf(stderr, "%3d > %3d (%5d > %5d)\n", ranks[i].i, ranks[i].j, ranks[i].Vij, ranks[i].Vji); } } if ( it->explain != NULL ) { fprintf((FILE*)it->explain, "<p>Initial pair rankings:</p><table border=\"0\">\n" ); for ( i = 0; i < x; ++i ) { fprintf((FILE*)it->explain, "<tr><td>%s</td><td>></td><td>%s</td><td>(%d > %d)</td></tr>\n", indexName(it->ni, ranks[i].i), indexName(it->ni, ranks[i].j), ranks[i].Vij, ranks[i].Vji); } fprintf((FILE*)it->explain, "</table>\n<p>"); } i = 1; while ( i < x ) { int equivalenceLimit = i; while ( (equivalenceLimit + 1) < x ) { if (pair_cmp(ranks + equivalenceLimit, ranks + (equivalenceLimit + 1))) { break; } ++equivalenceLimit; } if ( findPath(ranks, equivalenceLimit, ranks[i].j, ranks[i].i, NULL) ) { // drop this link as there is a pre-existing reverse path if ( verbose ) { fprintf(stderr, "DROP: %3d > %3d (%5d > %5d)\n", ranks[i].i, ranks[i].j, ranks[i].Vij, ranks[i].Vji); } if ( it->explain != NULL ) { fprintf((FILE*)it->explain, "DROP: %s > %s (%d > %d)<br />\n", indexName(it->ni, ranks[i].i), indexName(it->ni, ranks[i].j), ranks[i].Vij, ranks[i].Vji); } ranks[i].active = 0; } ++i; } if ( it->explain != NULL ) { fprintf((FILE*)it->explain, "</p><p>Final pair rankings:</p><table border=\"0\">\n" ); for ( i = 0; i < x; ++i ) { fprintf((FILE*)it->explain, "<tr%s><td>%s</td><td>></td><td>%s</td><td>(%d > %d)</td></tr>\n", (ranks[i].active ? "" : " style=\"color: #999999\""), indexName(it->ni, ranks[i].i), indexName(it->ni, ranks[i].j), ranks[i].Vij, ranks[i].Vji); } fprintf((FILE*)it->explain, "</table>\n"); } for ( i = 0; i < numc; ++i ) { defeatCount[i] = 0; } for ( i = 0; i < x; ++i ) { if ( ranks[i].active ) { defeatCount[ranks[i].j]++; } } VRR_makeWinners( it, defeatCount ); free( defeatCount ); return VRR_returnWinners( it, winnersLength, winnersP ); }
// I believe this correctly implements Cloneproof Schwartz Set Dropping, aka // the Schulze method. // http://wiki.electorama.com/wiki/Schulze_method static int VRR_CSSD( VRR* it, int winnersLength, NameVote** winnersP, int* defeatCount ) { int numc = it->numc; int i, j; int* tally; int* ss; minij* mins; int numWinners; int mind; // minimum defeat, index and strength int tie = 0; if ( debug ) { fprintf(stderr,"pre cssd defeat count:"); for ( i = 0; i < numc; i++ ) { fprintf(stderr," %d", defeatCount[i] ); } fprintf(stderr,"\n"); } tally = malloc( sizeof(int)*numc*numc ); assert( tally != NULL ); ss = malloc( sizeof(int)*numc ); assert( ss != NULL ); mins = malloc( sizeof(minij)*numc ); assert( mins != NULL ); // Copy original VRR tally into local tally where defeats can be deleted. for ( i = 0; i < numc; i++ ) { for ( j = 0; j < numc; j++ ) { if ( i != j ) { tally[i*numc+j] = xy(i,j); } else { //tally[i*numc+j] = -1; // i==j should never be accessed } } } numWinners = getSchwartzSet( it, tally, defeatCount, ss ); while ( 1 ) { int ji, ki; mind = INT_MAX; tie = 0; if ( it->explain != NULL ) { assert(numWinners > 0); fprintf((FILE*)it->explain, "<p>Top choices: %s", indexName(it->ni, ss[0])); for ( i = 1; i < numWinners; ++i ) { fprintf((FILE*)it->explain, ", %s", indexName(it->ni, ss[i]) ); } fprintf((FILE*)it->explain, "</p>"); } if ( debug ) { printTally(stdout,tally,numc); fprintf(stderr,"ss (%d):", numWinners ); for ( i = 0; i < numWinners; i++ ) { fprintf(stderr," %d", ss[i] ); } fprintf(stderr,"\n"); } // find weakest defeat between members of schwartz set for ( ji = 0; ji < numWinners - 1; ji++ ) { j = ss[ji]; for ( ki = ji + 1; ki < numWinners; ki++ ) { int k; int vj, vk; int ihi, ilo; int vhi, vlo; int m; k = ss[ki]; vk = tally[k*numc + j]; // k beat j vk times // OR k prefered to j vk times vj = tally[j*numc + k]; // j beat k vj times // OR j prefered to k vj times if ((vk == -1) && (vj == -1)) { continue; } if ( vk > vj ) { ihi = k; ilo = j; vhi = vk; vlo = vj; } else /*if ( vj > vk )*/ { // A tie is indeed a weak defeat, probably the weakest, and // it doesn't matter in which direction it is considered for deletion. ihi = j; ilo = k; vhi = vj; vlo = vk; } if ( winningVotes ) { m = vhi; } else if ( margins ) { m = vhi - vlo; } else { assert(0); } if ( m < mind ) { tie = 1; mind = m; mins[0].ihi = ihi; mins[0].ilo = ilo; } else if ( m == mind ) { mins[tie].ihi = ihi; mins[tie].ilo = ilo; tie++; } } } if ( tie == 0 ) { if ( debug ) { fprintf(stderr, "tie = 0, no weakest defeat found to cancel\n"); } goto finish; } // all are tied if ( tie == numWinners) { if ( debug ) { fprintf(stderr, "tie==numWinners==%d, mind=%d\n", tie, mind); } goto finish; } for ( i = 0; i < tie; ++i ) { int mindk = mins[i].ihi; int mindj = mins[i].ilo; if ( it->explain != NULL ) { fprintf((FILE*)it->explain, "<p>Weakest defeat is %s (%d) v %s (%d). %s has one fewer defeat.</p>\n", indexName(it->ni, mindk), tally[mindk*numc + mindj], indexName(it->ni, mindj), tally[mindj*numc + mindk], indexName(it->ni, mindj) ); } tally[mindk*numc + mindj] = -1; tally[mindj*numc + mindk] = -1; defeatCount[mindj]--; } numWinners = getSchwartzSet( it, tally, defeatCount, ss ); if ( numWinners == 1 ) { goto finish; } if ( debug ) { assert(numWinners > 0); fprintf(stderr, "ss={ %d", ss[0] ); for ( j = 1; j < numWinners; j++ ) { fprintf(stderr, ", %d", ss[j] ); } fprintf(stderr, " }\n"); } } finish: free( mins ); free( ss ); free( tally ); VRR_makeWinners( it, defeatCount ); free( defeatCount ); return VRR_returnWinners( it, winnersLength, winnersP ); }
int IRNR::getWinners( int numVotes, NameVote** votes ) { int numActive = numNames(); assert(votes != NULL); if ((numVotes == 0) || (*votes == NULL)) { *votes = new NameVote[numActive]; numVotes = numActive; } if ( tally != NULL ) { delete tally; } tally = new double[numNames()]; bool* active = new bool[numNames()]; int i; int toret = -1; for ( i = 0; i < numNames(); i++ ) { active[i] = true; } while ( numActive > 1 ) { // init tally and count it for ( i = 0; i < numNames(); i++ ) { tally[i] = 0.0; } { StoredIndexVoteNode* cur; cur = storedVotes; while ( cur != NULL ) { double sum; sum = 0.0; for ( i = 0; i < cur->numVotes; i++ ) { if ( active[cur->vote[i].index] ) { sum += fabs( cur->vote[i].rating ); } } if ( sum > 0.0 ) { // many multiplies are faster, specially if there's a madd sum = 1.0 / sum; for ( i = 0; i < cur->numVotes; i++ ) { if ( active[cur->vote[i].index] ) { tally[cur->vote[i].index] += cur->vote[i].rating * sum; } } } cur = cur->next; } } #if 0 for ( i = 0; i < numNames(); i++ ) { printf("\t\"%s\" = %g\n", indexName( i ), tally[i] ); } #endif // disqualify loser(s) { double min; int tied; for ( i = 0; ! active[i]; i++ ) { } min = tally[i]; tied = 1; i++; for ( ; i < numNames(); i++ ) { if ( ! active[i] ) { // skip } else if ( tally[i] < min ) { min = tally[i]; tied = 1; } else if ( tally[i] == min ) { tied++; } } if ( tied == numActive ) { // last N are tied, return them all break; } for ( i = 0; i < numNames(); i++ ) { if ( tally[i] == min ) { //printf("disqualify \"%s\" with %g\n", indexName( i ), tally[i] ); active[i] = false; numActive--; if ( numActive < numVotes ) { (*votes)[numActive].name = indexName( i ); (*votes)[numActive].rating = tally[i]; } } } } } toret = numActive; for ( i = 0; i < numNames(); i++ ) { if ( active[i] == true ) { numActive--; if ( numActive < numVotes ) { (*votes)[numActive].name = indexName( i ); (*votes)[numActive].rating = tally[i]; } } } delete [] active; return toret; }