void TreeItem::insertChild(TreeItem *child) { int index = nameIndex(child->data(0).toString()); m_children.insert(index, child); child->setParentTree(this); }
/* Return 0 on success, -1 on failure */ int SexpVecVector_setbyname(SEXP sexp, const char *name, SEXP value) { if (TYPEOF(sexp) != VECSXP) { printf("Not an R vector of type VECSXP.\n"); return -1; } R_len_t i = nameIndex(sexp, name); if (i == R_NaInt) { return -1; } else { SET_VECTOR_ELT(sexp, (R_len_t)i, value); return 0; } }
/* Return NULL on failure */ SEXP SexpVecVector_getbyname(const SEXP sexp, char *name) { if (TYPEOF(sexp) != VECSXP) { printf("Not an R vector of type VECSXP.\n"); return NULL; } R_len_t i = nameIndex(sexp, name); SEXP sexp_item; if (i != R_NaInt) { sexp_item = VECTOR_ELT(sexp, i); R_PreserveObject(sexp_item); } else { sexp_item = NULL; } return sexp_item; }
//! Writes attributes of the element. void CGUIButton::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const { IGUIButton::serializeAttributes(out,options); out->addBool ("PushButton", IsPushButton ); if (IsPushButton) out->addBool("Pressed", Pressed); for ( u32 i=0; i<(u32)EGBIS_COUNT; ++i ) { if ( ButtonImages[i].Texture ) { core::stringc name( GUIButtonImageStateNames[i] ); out->addTexture(name.c_str(), ButtonImages[i].Texture); name += "Rect"; out->addRect(name.c_str(), ButtonImages[i].SourceRect); } } out->addBool ("UseAlphaChannel", UseAlphaChannel); out->addBool ("Border", DrawBorder); out->addBool ("ScaleImage", ScaleImage); for ( u32 i=0; i<(u32)EGBS_COUNT; ++i ) { if ( ButtonSprites[i].Index >= 0 ) { core::stringc nameIndex( GUIButtonStateNames[i] ); nameIndex += "Index"; out->addInt(nameIndex.c_str(), ButtonSprites[i].Index ); core::stringc nameColor( GUIButtonStateNames[i] ); nameColor += "Color"; out->addColor(nameColor.c_str(), ButtonSprites[i].Color ); core::stringc nameLoop( GUIButtonStateNames[i] ); nameLoop += "Loop"; out->addBool(nameLoop.c_str(), ButtonSprites[i].Loop ); core::stringc nameScale( GUIButtonStateNames[i] ); nameScale += "Scale"; out->addBool(nameScale.c_str(), ButtonSprites[i].Scale ); } } // out->addString ("OverrideFont", OverrideFont); }
//! Reads attributes of the element void CGUIButton::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) { IGUIButton::deserializeAttributes(in,options); IsPushButton = in->getAttributeAsBool("PushButton", IsPushButton); Pressed = IsPushButton ? in->getAttributeAsBool("Pressed", Pressed) : false; for ( u32 i=0; i<(u32)EGBIS_COUNT; ++i ) { core::stringc nameRect( GUIButtonImageStateNames[i] ); nameRect += "Rect"; setImage((EGUI_BUTTON_IMAGE_STATE)i, in->getAttributeAsTexture(GUIButtonImageStateNames[i], ButtonImages[i].Texture), in->getAttributeAsRect(nameRect.c_str(), ButtonImages[i].SourceRect) ); } setDrawBorder(in->getAttributeAsBool("Border", DrawBorder)); setUseAlphaChannel(in->getAttributeAsBool("UseAlphaChannel", UseAlphaChannel)); setScaleImage(in->getAttributeAsBool("ScaleImage", ScaleImage)); for ( u32 i=0; i<(u32)EGBS_COUNT; ++i ) { core::stringc nameIndex( GUIButtonStateNames[i] ); nameIndex += "Index"; ButtonSprites[i].Index = in->getAttributeAsInt(nameIndex.c_str(), ButtonSprites[i].Index ); core::stringc nameColor( GUIButtonStateNames[i] ); nameColor += "Color"; ButtonSprites[i].Color = in->getAttributeAsColor(nameColor.c_str(), ButtonSprites[i].Color ); core::stringc nameLoop( GUIButtonStateNames[i] ); nameLoop += "Loop"; ButtonSprites[i].Loop = in->getAttributeAsBool(nameLoop.c_str(), ButtonSprites[i].Loop ); core::stringc nameScale( GUIButtonStateNames[i] ); nameScale += "Scale"; ButtonSprites[i].Scale = in->getAttributeAsBool(nameScale.c_str(), ButtonSprites[i].Scale ); } // setOverrideFont(in->getAttributeAsString("OverrideFont")); updateAbsolutePosition(); }
static void VRR_condorcetTable( VRR* it, FILE* fout, int numw, NameVote* winners ) { int i, xi, xj; int* indextr; fprintf( fout, "<table border=\"1\"><tr><td></td>" ); for ( i = 0; i < numw; i++ ) { fprintf( fout, "<td>(%d)</td>", i ); } fprintf( fout, "</tr>" ); indextr = (int*)malloc( sizeof(int)*numw ); assert( indextr != NULL ); for ( i = 0; i < numw; i++ ) { indextr[i] = nameIndex( it->ni, winners[i].name ); } for ( xi = 0; xi < numw; xi++ ) { i = indextr[xi]; fprintf( fout, "<tr><td>(%d) %s</td>", xi, winners[xi].name ); for ( xj = 0; xj < numw; xj++ ) { int j; j = indextr[xj]; if ( i == j ) { fprintf( fout, "<td></td>" ); } else { int thisw, otherw; thisw = xy(i,j); otherw = xy(j,i); if ( thisw > otherw ) { fprintf( fout, "<td bgcolor=\"#bbffbb\">"); } else if ( thisw < otherw ) { fprintf( fout, "<td bgcolor=\"#ffbbbb\">"); } else { fprintf( fout, "<td>"); } fprintf( fout, "%d</td>", thisw ); } } fprintf( fout, "</tr>" ); } free( indextr ); indextr = NULL; fprintf( fout, "</table>" ); }
int VRR_voteRating( VRR* it, int votesLength, const NameVote* votes ) { int i, j; int indexes[votesLength]; if ( it->winners != NULL ) { free( it->winners ); it->winners = NULL; } // preload indexes, only do lookup n, not (n^2)/2 for ( i = 0; i < votesLength; i++ ) { int x; x = nameIndex( it->ni, votes[i].name ); if ( x > it->numc ) { int err; err = growVRR( it, x ); if ( err != 0 ) { return err; } } indexes[i] = x; // vote vs unvoted dummy if ( votes[i].rating >= 0 ) { incxy( x, it->numc + 1 ); } else { incxy( it->numc + 1, x ); } } for ( i = 0; i < votesLength; i++ ) { for ( j = i + 1; j < votesLength; j++ ) { if ( votes[i].rating > votes[j].rating ) { incxy(indexes[i],indexes[j]); } else if ( votes[j].rating > votes[i].rating ) { incxy(indexes[j],indexes[i]); } else { // tie rating policy? } } } // All names not voted assumed to rate -0, lose to names with >= 0 ratings and beat < 0 ratings. i = voteUnvoted( it, votesLength, votes, indexes, it->ni->root ); return i; }
void voteLine( char* line, NameIndex* ni ) { StoredIndexVoteNode* x; int i; if ( preindexed ) { x = newStoredIndexVoteNodeFromIndexURL(line); for ( i = 0; i < x->numVotes; i++ ) { while ( x->vote[i].index >= ni->nextIndex ) { char* name = (char*)malloc(12); snprintf(name,12,"%d",ni->nextIndex); nameIndex( ni, name ); } } } else { x = newStoredIndexVoteNodeFromURL(ni,line); } if ( x == NULL ) { fprintf(stderr, "error parsing vote line:\n\t%s\n", line ); return; } if ( inputIsRankings ) { convertRankingsAndRatings(x); } //printf("read vote of %d name-rating pairs\n", x->numVotes ); if ( redumpVotes ) { char* reconst; reconst = storedIndexVoteToURL( ni, x ); printf("%s\n", reconst ); free(reconst); } for ( i = 0; i < numSystems; i++ ) { StoredIndexVoteNode* use; if ( i + 1 < numSystems ) { use = dupStoredIndexVoteNode( x ); } else { // consume x on last system use = x; } systems[i]->voteStoredIndexVoteNode( systems[i]->it, use ); } }
void HPACKEncoder::encodeAsLiteral(const HPACKHeader& header) { bool indexing = header.isIndexable(); uint8_t prefix = indexing ? HPACK::HeaderEncoding::LITERAL_INCR_INDEXING : HPACK::HeaderEncoding::LITERAL_NO_INDEXING; // name uint32_t index = nameIndex(header.name); if (index) { buffer_.encodeInteger(index, prefix, 6); } else { buffer_.encodeInteger(0, prefix, 6); buffer_.encodeLiteral(header.name); } // value buffer_.encodeLiteral(header.value); // indexed ones need to get added to the header table if (indexing) { if (table_.add(header)) { table_.addReference(1); } } }
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; }
void NamesView::MouseMoved (BPoint myPoint, uint32 transitcode, const BMessage *dragMessage) { if ((dragMessage != NULL) && (dragMessage->HasRef("refs"))) { // make sure the ref isn't a dir entry_ref ref; dragMessage->FindRef("refs", &ref); BDirectory dir (&ref); if (dir.InitCheck() != B_OK) { int32 nameIndex (IndexOf(myPoint)); if (nameIndex >= 0) Select(nameIndex); } } else if (fTracking) { if (transitcode == B_INSIDE_VIEW) { BListItem *item = ItemAt (IndexOf(myPoint)); if (item) { BListItem *lastitem (NULL); int32 first (CurrentSelection (0)); int32 last (first); int32 i (1); while ((last = CurrentSelection(i++)) != -1) lastitem = ItemAt(last); if (lastitem) last = IndexOf(lastitem); else last = first; int32 current (IndexOf (myPoint)); if (current >= 0) { if (current < first) { // sweep up Select (current, last, true); } else if (current > last) { // sweep down Select (first, current, true); } else if (fCurrentindex > current) { // backtrack up DeselectExcept (first, current); } else if (fCurrentindex < current) { // backtrack down DeselectExcept (current, last); } fCurrentindex = current; } } } } else BListView::MouseMoved (myPoint, transitcode, dragMessage); }