bool CharacterData::rendererIsNeeded(const NodeRenderingContext& context) { if (!m_data || !length()) return false; return Node::rendererIsNeeded(context); }
/* check neighbourhood sets and markov blanets for consistency.. */ SEXP bn_recovery(SEXP bn, SEXP strict, SEXP mb, SEXP filter, SEXP debug) { int i = 0, j = 0, k = 0, n = 0, counter = 0; short int *checklist = NULL, err = 0; int debuglevel = isTRUE(debug), checkmb = isTRUE(mb), *flt = INTEGER(filter); SEXP temp, temp2, nodes, elnames = NULL, fixed; /* get the names of the nodes. */ nodes = getAttrib(bn, R_NamesSymbol); n = length(nodes); /* allocate and initialize the checklist. */ checklist = allocstatus(UPTRI_MATRIX(n)); if (debuglevel > 0) { Rprintf("----------------------------------------------------------------\n"); if (checkmb) Rprintf("* checking consistency of markov blankets.\n"); else Rprintf("* checking consistency of neighbourhood sets.\n"); }/*THEN*/ /* scan the structure to determine the number of arcs. */ for (i = 0; i < n; i++) { if (debuglevel > 0) Rprintf(" > checking node %s.\n", NODE(i)); /* get the entry for the (neighbours|elements of the markov blanket) of the node.*/ temp = getListElement(bn, (char *)NODE(i)); if (!checkmb) temp = getListElement(temp, "nbr"); /* check each element of the array and identify which variable it corresponds to. */ for (j = 0; j < length(temp); j++) { for (k = 0; k < n; k++) { /* increment the right element of checklist. */ if (!strcmp(NODE(k), (char *)CHAR(STRING_ELT(temp, j)))) checklist[UPTRI(i + 1, k + 1, n)]++; }/*FOR*/ }/*FOR*/ }/*FOR*/ /* if A is a neighbour of B, B is a neighbour of A; therefore each entry in * the checklist array must be equal to either zero (if the corresponding * nodes are not neighbours) or two (if the corresponding nodes are neighbours). * Any other value (typically one) is caused by an incorrect (i.e. asymmetric) * neighbourhood structure. The same logic holds for the markov blankets. */ for (i = 0; i < n; i++) for (j = i; j < n; j++) { if ((checklist[UPTRI(i + 1, j + 1, n)] != 0) && (checklist[UPTRI(i + 1, j + 1, n)] != 2)) { if (debuglevel > 0) { if (checkmb) Rprintf("@ asymmetry in the markov blankets for %s and %s.\n", NODE(i), NODE(j)); else Rprintf("@ asymmetry in the neighbourhood sets for %s and %s.\n", NODE(i), NODE(j)); }/*THEN*/ err = 1; }/*THEN*/ }/*FOR*/ /* no need to go on if the (neighbourhood sets|markov blankets) are symmetric; * otherwise throw either an error or a warning according to the value of the * strict parameter. */ if (!err) { return bn; }/*THEN*/ else if (isTRUE(strict)) { if (checkmb) error("markov blankets are not symmetric.\n"); else error("neighbourhood sets are not symmetric.\n"); }/*THEN*/ /* build a correct structure to return. */ PROTECT(fixed = allocVector(VECSXP, n)); setAttrib(fixed, R_NamesSymbol, nodes); /* allocate colnames. */ if (!checkmb) PROTECT(elnames = mkStringVec(2, "mb", "nbr")); for (i = 0; i < n; i++) { if (!checkmb) { /* allocate the "mb" and "nbr" elements of the node. */ PROTECT(temp = allocVector(VECSXP, 2)); SET_VECTOR_ELT(fixed, i, temp); setAttrib(temp, R_NamesSymbol, elnames); /* copy the "mb" part from the old structure. */ temp2 = getListElement(bn, (char *)NODE(i)); temp2 = getListElement(temp2, "mb"); SET_VECTOR_ELT(temp, 0, temp2); }/*THEN*/ /* rescan the checklist. */ for (j = 0; j < n; j++) if (checklist[UPTRI(i + 1, j + 1, n)] >= *flt) if (i != j) counter++; /* allocate and fill the "nbr" element. */ PROTECT(temp2 = allocVector(STRSXP, counter)); for (j = 0; j < n; j++) if (checklist[UPTRI(i + 1, j + 1, n)] == *flt) if (i != j) SET_STRING_ELT(temp2, --counter, STRING_ELT(nodes, j)); if (checkmb) { SET_VECTOR_ELT(fixed, i, temp2); UNPROTECT(1); }/*THEN*/ else { SET_VECTOR_ELT(temp, 1, temp2); UNPROTECT(2); }/*ELSE*/ }/*FOR*/ if (checkmb) UNPROTECT(1); else UNPROTECT(2); return fixed; }/*BN_RECOVERY*/
void deletenth(int nth) { printf("%s: %d - ", __FUNCTION__, nth); NODE *cur = head; NODE *temp = cur; int l = length(); if (head == NULL) { assert(tail == NULL); printf("Empty list \n"); return; } if ( nth <= 0 || nth > l) { printf("%d Invalid nth \n", nth); return; } if (nth == 1) { // there is only one node available in this list // and we're deleting that if (head == tail) { head = tail = NULL; printf(" %d deleted \n", temp->data); free(temp); return; } head = head->next; head->prev = NULL; printf(" %d deleted \n", temp->data); free(temp); return; } // If nth is the last node, then delete that // and adjust the tail pointer if (nth == l) { if (head == tail) { head = tail = NULL; printf(" %d deleted \n", temp->data); free(temp); return; } temp = tail; tail = tail->prev; tail->next = NULL; printf(" %d deleted \n", temp->data); free(temp); return; } --nth; while (--nth) cur = cur->next; temp = cur->next; cur->next = cur->next->next; cur->next->prev = cur; printf(" %d deleted \n", temp->data); free(temp); return; }
bool List::empty() { return length() == 0; }
void List::pop() { resize(length() - 1); }
/* * plr_SPI_prepare - The builtin SPI_prepare command for the R interpreter */ SEXP plr_SPI_prepare(SEXP rsql, SEXP rargtypes) { const char *sql; int nargs; int i; Oid *typeids = NULL; Oid *typelems = NULL; FmgrInfo *typinfuncs = NULL; void *pplan = NULL; void *saved_plan; saved_plan_desc *plan_desc; SEXP result; MemoryContext oldcontext; PREPARE_PG_TRY; /* set up error context */ PUSH_PLERRCONTEXT(rsupport_error_callback, "pg.spi.prepare"); /* switch to long lived context to create plan description */ oldcontext = MemoryContextSwitchTo(TopMemoryContext); plan_desc = (saved_plan_desc *) palloc(sizeof(saved_plan_desc)); MemoryContextSwitchTo(oldcontext); PROTECT(rsql = AS_CHARACTER(rsql)); sql = CHAR(STRING_ELT(rsql, 0)); UNPROTECT(1); if (sql == NULL) error("%s", "cannot prepare empty query"); PROTECT(rargtypes = AS_INTEGER(rargtypes)); if (!isVector(rargtypes) || !isInteger(rargtypes)) error("%s", "second parameter must be a vector of PostgreSQL datatypes"); /* deal with case of no parameters for the prepared query */ if (rargtypes == R_MissingArg || INTEGER(rargtypes)[0] == NA_INTEGER) nargs = 0; else nargs = length(rargtypes); if (nargs < 0) /* can this even happen?? */ error("%s", "second parameter must be a vector of PostgreSQL datatypes"); if (nargs > 0) { /* switch to long lived context to create plan description elements */ oldcontext = MemoryContextSwitchTo(TopMemoryContext); typeids = (Oid *) palloc(nargs * sizeof(Oid)); typelems = (Oid *) palloc(nargs * sizeof(Oid)); typinfuncs = (FmgrInfo *) palloc(nargs * sizeof(FmgrInfo)); MemoryContextSwitchTo(oldcontext); for (i = 0; i < nargs; i++) { int16 typlen; bool typbyval; char typdelim; Oid typinput, typelem; char typalign; FmgrInfo typinfunc; typeids[i] = INTEGER(rargtypes)[i]; /* switch to long lived context to create plan description elements */ oldcontext = MemoryContextSwitchTo(TopMemoryContext); get_type_io_data(typeids[i], IOFunc_input, &typlen, &typbyval, &typalign, &typdelim, &typelem, &typinput); typelems[i] = get_element_type(typeids[i]); MemoryContextSwitchTo(oldcontext); /* perm_fmgr_info already uses TopMemoryContext */ perm_fmgr_info(typinput, &typinfunc); typinfuncs[i] = typinfunc; } } else typeids = NULL; UNPROTECT(1); /* switch to SPI memory context */ SWITCHTO_PLR_SPI_CONTEXT(oldcontext); /* * trap elog/ereport so we can let R finish up gracefully * and generate the error once we exit the interpreter */ PG_TRY(); { /* Prepare plan for query */ pplan = SPI_prepare(sql, nargs, typeids); } PLR_PG_CATCH(); PLR_PG_END_TRY(); if (pplan == NULL) { char buf[128]; char *reason; switch (SPI_result) { case SPI_ERROR_ARGUMENT: reason = "SPI_ERROR_ARGUMENT"; break; case SPI_ERROR_UNCONNECTED: reason = "SPI_ERROR_UNCONNECTED"; break; case SPI_ERROR_COPY: reason = "SPI_ERROR_COPY"; break; case SPI_ERROR_CURSOR: reason = "SPI_ERROR_CURSOR"; break; case SPI_ERROR_TRANSACTION: reason = "SPI_ERROR_TRANSACTION"; break; case SPI_ERROR_OPUNKNOWN: reason = "SPI_ERROR_OPUNKNOWN"; break; default: snprintf(buf, sizeof(buf), "unknown RC %d", SPI_result); reason = buf; break; } /* internal error */ error("SPI_prepare() failed: %s", reason); } /* SPI_saveplan already uses TopMemoryContext */ saved_plan = SPI_saveplan(pplan); if (saved_plan == NULL) { char buf[128]; char *reason; switch (SPI_result) { case SPI_ERROR_ARGUMENT: reason = "SPI_ERROR_ARGUMENT"; break; case SPI_ERROR_UNCONNECTED: reason = "SPI_ERROR_UNCONNECTED"; break; default: snprintf(buf, sizeof(buf), "unknown RC %d", SPI_result); reason = buf; break; } /* internal error */ error("SPI_saveplan() failed: %s", reason); } /* back to caller's memory context */ MemoryContextSwitchTo(oldcontext); /* no longer need this */ SPI_freeplan(pplan); plan_desc->saved_plan = saved_plan; plan_desc->nargs = nargs; plan_desc->typeids = typeids; plan_desc->typelems = typelems; plan_desc->typinfuncs = typinfuncs; result = R_MakeExternalPtr(plan_desc, R_NilValue, R_NilValue); POP_PLERRCONTEXT; return result; }
/* * Takes the prepared plan rsaved_plan and creates a cursor * for it using the values specified in ragvalues. * */ SEXP plr_SPI_cursor_open(SEXP cursor_name_arg,SEXP rsaved_plan, SEXP rargvalues) { saved_plan_desc *plan_desc = (saved_plan_desc *) R_ExternalPtrAddr(rsaved_plan); void *saved_plan = plan_desc->saved_plan; int nargs = plan_desc->nargs; Oid *typeids = plan_desc->typeids; FmgrInfo *typinfuncs = plan_desc->typinfuncs; int i; Datum *argvalues = NULL; char *nulls = NULL; bool isnull = false; SEXP obj; SEXP result = NULL; MemoryContext oldcontext; char cursor_name[64]; Portal portal=NULL; PREPARE_PG_TRY; PUSH_PLERRCONTEXT(rsupport_error_callback, "pg.spi.cursor_open"); /* Divide rargvalues */ if (nargs > 0) { if (!Rf_isVectorList(rargvalues)) error("%s", "second parameter must be a list of arguments " \ "to the prepared plan"); if (length(rargvalues) != nargs) error("list of arguments (%d) is not the same length " \ "as that of the prepared plan (%d)", length(rargvalues), nargs); argvalues = (Datum *) palloc(nargs * sizeof(Datum)); nulls = (char *) palloc(nargs * sizeof(char)); } for (i = 0; i < nargs; i++) { PROTECT(obj = VECTOR_ELT(rargvalues, i)); argvalues[i] = get_scalar_datum(obj, typeids[i], typinfuncs[i], &isnull); if (!isnull) nulls[i] = ' '; else nulls[i] = 'n'; UNPROTECT(1); } strncpy(cursor_name, CHAR(STRING_ELT(cursor_name_arg,0)), 64); /* switch to SPI memory context */ SWITCHTO_PLR_SPI_CONTEXT(oldcontext); /* * trap elog/ereport so we can let R finish up gracefully * and generate the error once we exit the interpreter */ PG_TRY(); { /* Open the cursor */ portal = SPI_cursor_open(cursor_name,saved_plan, argvalues, nulls,1); } PLR_PG_CATCH(); PLR_PG_END_TRY(); /* back to caller's memory context */ MemoryContextSwitchTo(oldcontext); if(portal==NULL) error("SPI_cursor_open() failed"); else result = R_MakeExternalPtr(portal, R_NilValue, R_NilValue); POP_PLERRCONTEXT; return result; }
static SEXP createRSymbolObject(SEXP sname, DL_FUNC f, R_RegisteredNativeSymbol *symbol, Rboolean withRegistrationInfo) { SEXP tmp, klass, sym, names; int n = (symbol->type != R_ANY_SYM) ? 4 : 3; int numProtects = 0; PROTECT(sym = allocVector(VECSXP, n)); numProtects++; PROTECT(names = allocVector(STRSXP, n)); numProtects++; if(!sname || sname == R_NilValue) { PROTECT(sname = mkString(symbol->symbol.call->name)); numProtects++; } SET_VECTOR_ELT(sym, 0, sname); SET_STRING_ELT(names, 0, mkChar("name")); SET_VECTOR_ELT(sym, 1, withRegistrationInfo && symbol && symbol->symbol.c && symbol->dll ? Rf_MakeRegisteredNativeSymbol(symbol) : Rf_MakeNativeSymbolRef(f)); SET_STRING_ELT(names, 1, mkChar("address")); if(symbol->dll) SET_VECTOR_ELT(sym, 2, Rf_MakeDLLInfo(symbol->dll)); SET_STRING_ELT(names, 2, mkChar("dll")); PROTECT(klass = allocVector(STRSXP, (symbol->type != R_ANY_SYM ? 2 : 1))); numProtects++; SET_STRING_ELT(klass, length(klass)-1, mkChar("NativeSymbolInfo")); if(n > 3) { /* Add the registration information: the number of arguments and the classname. */ int nargs = -1; char *className = ""; switch(symbol->type) { case R_C_SYM: nargs = symbol->symbol.c->numArgs; className = "CRoutine"; break; case R_CALL_SYM: nargs = symbol->symbol.call->numArgs; className = "CallRoutine"; break; case R_FORTRAN_SYM: nargs = symbol->symbol.fortran->numArgs; className = "FortranRoutine"; break; case R_EXTERNAL_SYM: nargs = symbol->symbol.external->numArgs; className = "ExternalRoutine"; break; default: /* Something unintended has happened if we get here. */ error(_("unimplemented type %d in 'createRSymbolObject'"), symbol->type); break; } SET_VECTOR_ELT(sym, 3, tmp = ScalarInteger(nargs)); SET_STRING_ELT(klass, 0, mkChar(className)); SET_STRING_ELT(names, 3, mkChar("numParameters")); } setAttrib(sym, R_ClassSymbol, klass); setAttrib(sym, R_NamesSymbol, names); UNPROTECT(numProtects); return(sym); }
// // Split in two // // eg "a.b.c.d.e" with strDelim == "." and iIndex == 1 gives "a" and "b.c.d.e" // "a.b.c.d.e" with strDelim == "." and iIndex == -2 gives "a.b.c" and "d.e" // bool WString::Split ( const WString& strDelim, WString* pstrLeft, WString* pstrRight, int iIndex ) const { // Check for self-overwrite if ( this == pstrLeft || this == pstrRight ) return WString ( *this ).Split ( strDelim, pstrLeft, pstrRight, iIndex ); assert ( iIndex ); bool bFromEnd = iIndex < 0; size_t ulPos; if ( !bFromEnd ) { ulPos = 0; for ( int i = 0 ; i < iIndex && ulPos != npos ; i++ ) { if ( i ) ulPos += strDelim.length (); if ( ulPos < length () ) { ulPos = find ( strDelim, ulPos ); } else { ulPos = npos; break; } } } else { ulPos = length (); for ( int i = 0 ; i < -iIndex && ulPos != npos ; i++ ) { if ( ulPos >= strDelim.length () ) { ulPos -= strDelim.length (); ulPos = rfind ( strDelim, ulPos ); } else { ulPos = npos; break; } } } if ( ulPos == npos ) { if ( pstrLeft ) *pstrLeft = bFromEnd ? L"" : c_str (); if ( pstrRight ) *pstrRight = bFromEnd ? c_str () : L""; return false; } if ( pstrLeft ) *pstrLeft = substr ( 0, ulPos ); if ( pstrRight ) *pstrRight = substr ( ulPos + strDelim.length (), length () - ( ulPos + strDelim.length () ) ); return true; }
void WaterBall::update(float dt) { if(state == WATERDROP_STATE_NONE) { return ; } else if(state == WATERDROP_STATE_FILL) { if(drops.size() < 10) { uint64_t now = rx_hrtime(); if(now >= spawn_timeout) { spawn_timeout = now + spawn_delay * 1000000ull; addRandomDrop(); /* if(drops.size() == 10) { printf("We reached N drops, flush!\n"); state = WATERDROP_STATE_FLUSH; flush_timeout = now + flush_delay * 1000000LLU; } */ } } } else if(state == WATERDROP_STATE_FLUSH) { #if 1 // Remove the water drop when we need to flush (see below for a version where we remove // water drops only when they are in a certain radius. uint64_t now = rx_hrtime(); if(now >= flush_timeout) { if(drops.size()) { drops.erase(drops.begin()); flush_timeout = now + flush_delay * 1000000ull; if(!drops.size()) { state = WATERDROP_STATE_FREE; } } else { state = WATERDROP_STATE_NORMAL; } } #endif } if(!drops.size()) { return ; } vec2 dir; float dist = 0.0f; float dist_sq = 0.0f; vec2 f = 0.0f; float radius = drops.size() * radius_per_drop; float radius_sq = radius * radius; float neighbor_dist = 1; float neighbor_dist_sq = neighbor_dist * neighbor_dist; // REPEL FORCES: #if 1 for(size_t i = 0; i < drops.size(); ++i) { WaterDrop& a = drops[i]; for(size_t j = i + i; j < drops.size(); ++j) { WaterDrop& b = drops[j]; dir = b.position - a.position; dist_sq = dot(dir, dir); if(dist_sq > neighbor_dist_sq) { continue; } if(dist_sq < 0.01) { continue; } dir = normalized(dir); f = repel_force * (1.0 - (1.0 / dist_sq)) * dir; a.forces -= f; b.forces += f; } } #endif // ATTRACT FORCES float max_speed_sq = max_speed * max_speed; float speed_sq; float k = 1.0f; uint64_t now = rx_hrtime(); std::vector<WaterDrop>::iterator it = drops.begin(); while(it != drops.end()) { WaterDrop& d = *it; { dir = position - d.position; dist = length(dir); if(dist < 0.01) { dist = 0.01; } if(dist > radius) { /* when the particle is outiside the radius, it's attracted a lot more to the center */ k = 15.0; } #if 0 // This is where we flush the water drops! if(state == WATERDROP_STATE_FLUSH && dist < radius) { if(now >= flush_timeout) { if(drops.size()) { it = drops.erase(drops.begin()); flush_timeout = now + flush_delay * 1000000ull; if(!drops.size()) { state = WATERDROP_STATE_FREE; break; } continue; } } } #endif dir /= dist; f = k * attract_force * (dist/radius) * dir; d.forces += f; } d.forces *= d.inv_mass * dt; d.velocity += d.forces * dt; d.position += d.velocity; d.forces = 0; // we do not add a fake drag force, but we limit the speed, this will make the // particles bounce forever. speed_sq = dot(d.velocity, d.velocity); if(speed_sq > max_speed_sq) { d.velocity = normalized(d.velocity); d.velocity *= max_speed; } ++it; } /* glBindBuffer(GL_ARRAY_BUFFER, basic_vbo); size_t bytes_needed = sizeof(WaterDrop) * drops.size(); if(bytes_needed > bytes_allocated) { glBufferData(GL_ARRAY_BUFFER, bytes_needed, drops[0].position.ptr(), GL_STREAM_DRAW); } else { glBufferSubData(GL_ARRAY_BUFFER, 0, bytes_needed, drops[0].position.ptr()); } */ }
int main(int argc, char *argv[]) { int i, s; list q; list1 q1; list2 q2; record d; personal f; record *ptr, *pt; personal *ptr2, *pt2; FILE *fp, *fp1, *fp2, *fp3, *fp4, *fp6, *fp8, *fp9, *fp10; fp1 = fopen("b.txt", "a+"); node2 *st2; init(&q); init1(&q1); init2(&q2); char a[48]; char br[32]; int m, posi, choice, roll, size, s1, s2, s3, s4, num, posii, yr, MIS; while(1) { choice = printmenu(); switch(choice) { case 1 : printf("\nEnter the Name, MIS, Branch, Year of student and the MIS before which you wish to insert the record :\n"); /*if it is the first record 'posi' can be anything*/ scanf(" %[^\n]%d%s%d%d", a, &m, br, &yr, &posi); fp = fopen("k.txt", "a+"); Add_academic(&q, a, m, br, posi, yr, fp); fclose(fp); print(&q); break; case 2 : printf("Enter the MIS of the student record to be deleted :\n"); scanf("%d", &posii); fp = fopen("k.txt", "a+"); fp4 = fopen("d.txt", "w+"); if(pt = delet_academic(&q, posii,fp,fp4)) { printf("Name:%s\n MIS:%d\n Branch:%s\n Year :%d\n", pt->name, pt->MIS, pt->branch, pt->year); } else { printf("INVALID ENTRY\n"); } print(&q); fclose(fp); fclose(fp4); break; case 3 : printf("Enter the MIS of student :\n"); scanf("%d", &roll); if(ptr = search(&q, roll)) { printf("\nName :%s\tMIS :%d\tBranch :%s\tYear :%d\n", ptr->name, ptr->MIS, ptr->branch, ptr->year); } else { printf("\nRECORD NOT FOUND\n"); } break; case 4 : printf("Enter the Name, MIS, Branch, Year of student :\n"); scanf(" %[^\n]%d%s%d", a, &m, br, &yr); fp = fopen("k.txt", "a+"); append_academic(&q, a, m, br, yr, fp); print(&q); fclose(fp); break; case 5 : size = length(&q); printf("Number of student records(academic) : %d\n", size); break; case 6 : printf("Enter the MIS of student :\n"); scanf("%d", &roll); creatingID(&q, roll); break; case 7 : fp = fopen("k.txt", "a+"); fp3 = fopen("a.txt", "r"); academicfromfile(&q, fp3, fp); print(&q); fclose(fp); fclose(fp3); break; case 8 : printf("Enter the Name, MIS, Branch and Year of student:\n"); scanf(" %[^\n]%d%s%d", a, &m, br, &yr); /*MIS should be same*/ fp = fopen("k.txt", "a+"); fp6 = fopen("n.txt", "w+"); Modify_academic(&q, m, a, br, yr, fp, fp6); print(&q); fclose(fp); fclose(fp6); break; case 9 : num = length1(&q1); printf("No of students who appeared for final exam : %d\n", num); break; case 10 : printf("Enter MIS, T1 marks of 4 subjects ,MIS before which you wish to enter the record and the semester :\n"); scanf("%d%d%d%d%d%d%d",&roll,&s1,&s2,&s3,&s4,&m, &i); T1Marks(&q1,roll,s1,s2,s3,s4,m,i); printT1(&q1, i); break; case 11 : printf("Enter MIS and T2 marks of 4 subjects and the semester :\n"); scanf("%d%d%d%d%d%d",&roll,&s1,&s2,&s3,&s4, &i); T2Marks(&q1,roll,s1,s2,s3,s4,i); printT2(&q1, i); break; case 12 : printf("Enter MIS and ESE marks of 4 subjects and the semester :\n"); scanf("%d%d%d%d%d%d",&roll,&s1,&s2,&s3,&s4,&i); ESEMarks(&q1,roll,s1,s2,s3,s4,i); printESE(&q1, i); break; case 13 : printf("Enter the MIS and the semester :\n"); scanf("%d%d", &MIS, &i); Total(&q1, MIS,i, fp1); printTOT(&q1, i); break; case 14 : printf("Enter the Name, MIS, Mobile no., Email Id of student and the MIS before which you wish to insert the record :\n"); /*if it is the first record, posi can be anything*/ scanf(" %[^\n]%d%d%s%d", a, &m, &yr, br, &posi); fp2 = fopen("c.txt", "a+"); Add2_personal(&q2, a, m, yr, br, posi, fp2); print2(&q2); fclose(fp2); break; case 15 : printf("Enter the MIS of the student record to be deleted :\n"); scanf("%d", &posii); fp2 = fopen("c.txt", "a+"); fp9 = fopen("s.txt", "w+"); if(pt2 = delet2_personal(&q2, posii,fp2, fp9)) { printf("Name:%s\n MIS:%d\n Mobile No:%d\n Email Id :%s\n", pt2->name, pt2->MISS, pt2->mobile, pt2->email_Id); } else { printf("INVALID ENTRY\n"); } print2(&q2); fclose(fp2); fclose(fp9); break; case 16 : printf("Enter the MIS of student :\n"); scanf("%d", &roll); if(ptr2 = search2(&q2, roll)) { printf("\nName :%s\tMIS :%d\tMobile No :%d\tEmail Id :%s\n", ptr2->name, ptr2->MISS, ptr2->mobile, ptr2->email_Id); } else { printf("\nRECORD NOT FOUND\n"); } break; case 17 : printf("Enter the Name, MIS, Mobile no. and Email Id of student:\n"); scanf(" %[^\n]%d%d%s", a, &m, &yr, br); /*MIS should be same*/ fp8 = fopen("w.txt", "w+"); fp2 = fopen("c.txt", "a+"); Modify2_personal(&q2, m, a, yr, br,fp2, fp8); print2(&q2); fclose(fp2); fclose(fp8); break; case 18 : printf("\nEnter the MIS of the student and the semester :\n"); scanf("%d%d", &m, &s); link(&q, &q1, &q2, m, s); break; case 19 : fp2 = fopen("c.txt", "a+"); fp10 = fopen("p.txt", "r"); personalfromfile(&q2, fp10, fp2); print2(&q2); fclose(fp2); fclose(fp10); break; case 20 : fclose(fp1); exit(1); break; } } }
inline Vec2 normalize(Vec2 v) { return v/=length(v); }
inline Vec3 normalize(Vec3 v) { return v/=length(v); }
static unsigned int ray_color(const point3 e, double t, const point3 d, idx_stack *stk, const rectangular_node rectangulars, const sphere_node spheres, const light_node lights, color object_color, int bounces_left) { rectangular_node hit_rec = NULL, light_hit_rec = NULL; sphere_node hit_sphere = NULL, light_hit_sphere = NULL; double diffuse, specular; point3 l, _l, r, rr; object_fill fill; color reflection_part; color refraction_part; /* might be a reflection ray, so check how many times we've bounced */ if (bounces_left == 0) { SET_COLOR(object_color, 0.0, 0.0, 0.0); return 0; } /* check for intersection with a sphere or a rectangular */ intersection ip= ray_hit_object(e, d, t, MAX_DISTANCE, rectangulars, &hit_rec, spheres, &hit_sphere); if (!hit_rec && !hit_sphere) return 0; /* pick the fill of the object that was hit */ fill = hit_rec ? hit_rec->element.rectangular_fill : hit_sphere->element.sphere_fill; void *hit_obj = hit_rec ? (void *) hit_rec : (void *) hit_sphere; /* assume it is a shadow */ SET_COLOR(object_color, 0.0, 0.0, 0.0); for (light_node light = lights; light; light = light->next) { /* calculate the intersection vector pointing at the light */ subtract_vector(ip.point, light->element.position, l); multiply_vector(l, -1, _l); normalize(_l); /* check for intersection with an object. use ignore_me * because we don't care about this normal */ ray_hit_object(ip.point, _l, MIN_DISTANCE, length(l), rectangulars, &light_hit_rec, spheres, &light_hit_sphere); /* the light was not block by itself(lit object) */ if (light_hit_rec || light_hit_sphere) continue; compute_specular_diffuse(&diffuse, &specular, d, l, ip.normal, fill.phong_power); localColor(object_color, light->element.light_color, diffuse, specular, &fill); } reflection(r, d, ip.normal); double idx = idx_stack_top(stk).idx, idx_pass = fill.index_of_refraction; if (idx_stack_top(stk).obj == hit_obj) { idx_stack_pop(stk); idx_pass = idx_stack_top(stk).idx; } else { idx_stack_element e = { .obj = hit_obj, .idx = fill.index_of_refraction }; idx_stack_push(stk, e); } refraction(rr, d, ip.normal, idx, idx_pass); double R = (fill.T > 0.1) ? fresnel(d, rr, ip.normal, idx, idx_pass) : 1.0; /* totalColor = localColor + mix((1-fill.Kd) * fill.R * reflection, T * refraction, R) */ if (fill.R > 0) { /* if we hit something, add the color */ int old_top = stk->top; if (ray_color(ip.point, MIN_DISTANCE, r, stk, rectangulars, spheres, lights, reflection_part, bounces_left - 1)) { multiply_vector(reflection_part, R * (1.0 - fill.Kd) * fill.R, reflection_part); add_vector(object_color, reflection_part, object_color); } stk->top = old_top; } /* calculate refraction ray */ if ((length(rr) > 0.0) && (fill.T > 0.0) && (fill.index_of_refraction > 0.0)) { normalize(rr); if (ray_color(ip.point, MIN_DISTANCE, rr, stk,rectangulars, spheres, lights, refraction_part, bounces_left - 1)) { multiply_vector(refraction_part, (1 - R) * fill.T, refraction_part); add_vector(object_color, refraction_part, object_color); } } protect_color_overflow(object_color); return 1; } static void *parallel (void* range1) { Thread_range *range = (Thread_range *)range1; point3 d; idx_stack stk; color object_color = { 0.0, 0.0, 0.0 }; for (int j = range->height1; j < range->height2; j++) { for (int i = 0; i < range->ptr->width; i++) { double r = 0, g = 0, b = 0; /* MSAA */ for (int s = 0; s < SAMPLES; s++) { idx_stack_init(&stk); rayConstruction(d, range->ptr->u, range->ptr->v, range->ptr->w, i * range->ptr->factor + s / range->ptr->factor, j * range->ptr->factor + s % range->ptr->factor, range->ptr->view, range->ptr->width * range->ptr->factor, range->ptr->height * range->ptr->factor); if (ray_color(range->ptr->view->vrp, 0.0, d, &(stk), range->ptr->rectangulars, range->ptr->spheres, range->ptr->lights, object_color, MAX_REFLECTION_BOUNCES)) { r += object_color[0]; g += object_color[1]; b += object_color[2]; } else { r += range->ptr->background_color[0]; g += range->ptr->background_color[1]; b += range->ptr->background_color[2]; } range->ptr->pixels[((i + (j * range->ptr->width)) * 3) + 0] = r * 255 / SAMPLES; range->ptr->pixels[((i + (j * range->ptr->width)) * 3) + 1] = g * 255 / SAMPLES; range->ptr->pixels[((i + (j * range->ptr->width)) * 3) + 2] = b * 255 / SAMPLES; } } } return NULL; }
bool full() const { return length() >= MAX_SIZE - 1; }
// Right most number of characters WString WString::Right ( int iCount ) const { return SubStr ( (int)length () - iCount, iCount ); }
/** * Truncate the string to the specified length. * * @param new_length the new length; must be equal or smaller than * the current length */ void Truncate(size_type new_length) { assert(new_length <= length()); data[new_length] = SENTINEL; }
/** * Returns one writable character. No bounds checking. */ T &operator[](size_type i) { assert(i <= length()); return data[i]; }
/* * plr_SPI_execp - The builtin SPI_execp command for the R interpreter */ SEXP plr_SPI_execp(SEXP rsaved_plan, SEXP rargvalues) { saved_plan_desc *plan_desc = (saved_plan_desc *) R_ExternalPtrAddr(rsaved_plan); void *saved_plan = plan_desc->saved_plan; int nargs = plan_desc->nargs; Oid *typeids = plan_desc->typeids; Oid *typelems = plan_desc->typelems; FmgrInfo *typinfuncs = plan_desc->typinfuncs; int i; Datum *argvalues = NULL; char *nulls = NULL; bool isnull = false; SEXP obj; int spi_rc = 0; char buf[64]; int count = 0; int ntuples; SEXP result = NULL; MemoryContext oldcontext; PREPARE_PG_TRY; /* set up error context */ PUSH_PLERRCONTEXT(rsupport_error_callback, "pg.spi.execp"); if (nargs > 0) { if (!Rf_isVectorList(rargvalues)) error("%s", "second parameter must be a list of arguments " \ "to the prepared plan"); if (length(rargvalues) != nargs) error("list of arguments (%d) is not the same length " \ "as that of the prepared plan (%d)", length(rargvalues), nargs); argvalues = (Datum *) palloc(nargs * sizeof(Datum)); nulls = (char *) palloc(nargs * sizeof(char)); } for (i = 0; i < nargs; i++) { PROTECT(obj = VECTOR_ELT(rargvalues, i)); argvalues[i] = get_datum(obj, typeids[i], typelems[i], typinfuncs[i], &isnull); if (!isnull) nulls[i] = ' '; else nulls[i] = 'n'; UNPROTECT(1); } /* switch to SPI memory context */ SWITCHTO_PLR_SPI_CONTEXT(oldcontext); /* * trap elog/ereport so we can let R finish up gracefully * and generate the error once we exit the interpreter */ PG_TRY(); { /* Execute the plan */ spi_rc = SPI_execp(saved_plan, argvalues, nulls, count); } PLR_PG_CATCH(); PLR_PG_END_TRY(); /* back to caller's memory context */ MemoryContextSwitchTo(oldcontext); /* check the result */ switch (spi_rc) { case SPI_OK_UTILITY: snprintf(buf, sizeof(buf), "%d", 0); SPI_freetuptable(SPI_tuptable); PROTECT(result = NEW_CHARACTER(1)); SET_STRING_ELT(result, 0, COPY_TO_USER_STRING(buf)); UNPROTECT(1); break; case SPI_OK_SELINTO: case SPI_OK_INSERT: case SPI_OK_DELETE: case SPI_OK_UPDATE: snprintf(buf, sizeof(buf), "%d", SPI_processed); SPI_freetuptable(SPI_tuptable); PROTECT(result = NEW_CHARACTER(1)); SET_STRING_ELT(result, 0, COPY_TO_USER_STRING(buf)); UNPROTECT(1); break; case SPI_OK_SELECT: ntuples = SPI_processed; if (ntuples > 0) { result = rpgsql_get_results(ntuples, SPI_tuptable); SPI_freetuptable(SPI_tuptable); } else result = R_NilValue; break; case SPI_ERROR_ARGUMENT: error("SPI_execp() failed: SPI_ERROR_ARGUMENT"); break; case SPI_ERROR_UNCONNECTED: error("SPI_execp() failed: SPI_ERROR_UNCONNECTED"); break; case SPI_ERROR_COPY: error("SPI_execp() failed: SPI_ERROR_COPY"); break; case SPI_ERROR_CURSOR: error("SPI_execp() failed: SPI_ERROR_CURSOR"); break; case SPI_ERROR_TRANSACTION: error("SPI_execp() failed: SPI_ERROR_TRANSACTION"); break; case SPI_ERROR_OPUNKNOWN: error("SPI_execp() failed: SPI_ERROR_OPUNKNOWN"); break; default: error("SPI_execp() failed: %d", spi_rc); break; } POP_PLERRCONTEXT; return result; }
const T *end() const { return data + length(); }
double sph_model::view_face(const double *M, int vw, int vh, double ee, double ww, double nn, double ss, int j) { double ne[3], a[3], e[3], A[4], E[4]; // North-east corner double nw[3], b[3], f[3], B[4], F[4]; // North-west corner double se[3], c[3], g[3], C[4], G[4]; // South-east corner double sw[3], d[3], h[3], D[4], H[4]; // South-west corner vnormalize(ne, cube_v[cube_i[j][0]]); vnormalize(nw, cube_v[cube_i[j][1]]); vnormalize(se, cube_v[cube_i[j][2]]); vnormalize(sw, cube_v[cube_i[j][3]]); bislerp(a, ne, nw, se, sw, ee, nn); bislerp(b, ne, nw, se, sw, ww, nn); bislerp(c, ne, nw, se, sw, ee, ss); bislerp(d, ne, nw, se, sw, ww, ss); zoom(a, a); zoom(b, b); zoom(c, c); zoom(d, d); // Compute the maximum extent due to bulge. double v[3]; v[0] = a[0] + b[0] + c[0] + d[0]; v[1] = a[1] + b[1] + c[1] + d[1]; v[2] = a[2] + b[2] + c[2] + d[2]; double k = vlen(v) / vdot(a, v); // Compute the outer corners of the bulge bound. vmul(e, a, k); vmul(f, b, k); vmul(g, c, k); vmul(h, d, k); // Compute W and reject any volume on the far side of the singularity. A[3] = M[ 3] * a[0] + M[ 7] * a[1] + M[11] * a[2] + M[15]; B[3] = M[ 3] * b[0] + M[ 7] * b[1] + M[11] * b[2] + M[15]; C[3] = M[ 3] * c[0] + M[ 7] * c[1] + M[11] * c[2] + M[15]; D[3] = M[ 3] * d[0] + M[ 7] * d[1] + M[11] * d[2] + M[15]; E[3] = M[ 3] * e[0] + M[ 7] * e[1] + M[11] * e[2] + M[15]; F[3] = M[ 3] * f[0] + M[ 7] * f[1] + M[11] * f[2] + M[15]; G[3] = M[ 3] * g[0] + M[ 7] * g[1] + M[11] * g[2] + M[15]; H[3] = M[ 3] * h[0] + M[ 7] * h[1] + M[11] * h[2] + M[15]; if (A[3] <= 0 && B[3] <= 0 && C[3] <= 0 && D[3] <= 0 && E[3] <= 0 && F[3] <= 0 && G[3] <= 0 && H[3] <= 0) return 0; // Compute Z and apply the near and far clipping planes. A[2] = M[ 2] * a[0] + M[ 6] * a[1] + M[10] * a[2] + M[14]; B[2] = M[ 2] * b[0] + M[ 6] * b[1] + M[10] * b[2] + M[14]; C[2] = M[ 2] * c[0] + M[ 6] * c[1] + M[10] * c[2] + M[14]; D[2] = M[ 2] * d[0] + M[ 6] * d[1] + M[10] * d[2] + M[14]; E[2] = M[ 2] * e[0] + M[ 6] * e[1] + M[10] * e[2] + M[14]; F[2] = M[ 2] * f[0] + M[ 6] * f[1] + M[10] * f[2] + M[14]; G[2] = M[ 2] * g[0] + M[ 6] * g[1] + M[10] * g[2] + M[14]; H[2] = M[ 2] * h[0] + M[ 6] * h[1] + M[10] * h[2] + M[14]; if (A[2] > A[3] && B[2] > B[3] && C[2] > C[3] && D[2] > D[3] && E[2] > E[3] && F[2] > F[3] && G[2] > G[3] && H[2] > H[3]) return 0; if (A[2] < -A[3] && B[2] < -B[3] && C[2] < -C[3] && D[2] < -D[3] && E[2] < -E[3] && F[2] < -F[3] && G[2] < -G[3] && H[2] < -H[3]) return 0; // Compute Y and apply the bottom and top clipping planes. A[1] = M[ 1] * a[0] + M[ 5] * a[1] + M[ 9] * a[2] + M[13]; B[1] = M[ 1] * b[0] + M[ 5] * b[1] + M[ 9] * b[2] + M[13]; C[1] = M[ 1] * c[0] + M[ 5] * c[1] + M[ 9] * c[2] + M[13]; D[1] = M[ 1] * d[0] + M[ 5] * d[1] + M[ 9] * d[2] + M[13]; E[1] = M[ 1] * e[0] + M[ 5] * e[1] + M[ 9] * e[2] + M[13]; F[1] = M[ 1] * f[0] + M[ 5] * f[1] + M[ 9] * f[2] + M[13]; G[1] = M[ 1] * g[0] + M[ 5] * g[1] + M[ 9] * g[2] + M[13]; H[1] = M[ 1] * h[0] + M[ 5] * h[1] + M[ 9] * h[2] + M[13]; if (A[1] > A[3] && B[1] > B[3] && C[1] > C[3] && D[1] > D[3] && E[1] > E[3] && F[1] > F[3] && G[1] > G[3] && H[1] > H[3]) return 0; if (A[1] < -A[3] && B[1] < -B[3] && C[1] < -C[3] && D[1] < -D[3] && E[1] < -E[3] && F[1] < -F[3] && G[1] < -G[3] && H[1] < -H[3]) return 0; // Compute X and apply the left and right clipping planes. A[0] = M[ 0] * a[0] + M[ 4] * a[1] + M[ 8] * a[2] + M[12]; B[0] = M[ 0] * b[0] + M[ 4] * b[1] + M[ 8] * b[2] + M[12]; C[0] = M[ 0] * c[0] + M[ 4] * c[1] + M[ 8] * c[2] + M[12]; D[0] = M[ 0] * d[0] + M[ 4] * d[1] + M[ 8] * d[2] + M[12]; E[0] = M[ 0] * e[0] + M[ 4] * e[1] + M[ 8] * e[2] + M[12]; F[0] = M[ 0] * f[0] + M[ 4] * f[1] + M[ 8] * f[2] + M[12]; G[0] = M[ 0] * g[0] + M[ 4] * g[1] + M[ 8] * g[2] + M[12]; H[0] = M[ 0] * h[0] + M[ 4] * h[1] + M[ 8] * h[2] + M[12]; if (A[0] > A[3] && B[0] > B[3] && C[0] > C[3] && D[0] > D[3] && E[0] > E[3] && F[0] > F[3] && G[0] > G[3] && H[0] > H[3]) return 0; if (A[0] < -A[3] && B[0] < -B[3] && C[0] < -C[3] && D[0] < -D[3] && E[0] < -E[3] && F[0] < -F[3] && G[0] < -G[3] && H[0] < -H[3]) return 0; // Compute the length of the longest visible edge, in pixels. // return max(length(A, B, vw, vh), // length(C, D, vw, vh), // length(A, C, vw, vh), // length(B, D, vw, vh)); return std::max(max(length(A, B, vw, vh), length(C, D, vw, vh), length(A, C, vw, vh), length(B, D, vw, vh)), max(length(E, F, vw, vh), length(G, H, vw, vh), length(E, G, vw, vh), length(F, H, vw, vh))); }
T last() const { assert(length() > 0); return data[length() - 1]; }
caValue* List::getLast() { return get(length() - 1); }
void append(const T *new_value) { assert(new_value != NULL); size_type len = length(); CopyString(data + len, new_value, MAX_SIZE - len); }
// helper routines to accelerate learning int counter_service_impl::get_learn_state(decree start, const blob& learn_request, __out_param learn_state& state) { ::dsn::binary_writer writer; zauto_lock l(_lock); int magic = 0xdeadbeef; writer.write(magic); writer.write(_last_committed_decree.load()); dassert(_last_committed_decree >= 0, ""); int count = static_cast<int>(_counters.size()); writer.write(count); for (auto it = _counters.begin(); it != _counters.end(); it++) { writer.write(it->first); writer.write(it->second); } auto bb = writer.get_buffer(); auto buf = bb.buffer(); state.meta.push_back(blob(buf, static_cast<int>(bb.data() - bb.buffer().get()), bb.length())); return ERR_SUCCESS; }
/** * Append ASCII characters from the specified string without buffer * boundary checks. */ void UnsafeAppendASCII(const char *p) { CopyASCII(data + length(), p); }
void addnth(int data, int nth) { printf("%s: %d %d ", __FUNCTION__, data, nth); NODE *newnode; NODE *cur = head; int l = length(); if (nth <= 0 || nth > l+1) { printf("Invalid nth \n"); return; } if (newnode = (NODE *) malloc(sizeof (NODE))) { newnode->data = data; newnode->next = NULL; newnode->prev = NULL; } else { printf("unable to allocate memory \n"); return; } if (nth == 1) { // If list is empty and nth is position #1 if (head == NULL) { assert (tail == NULL); head = tail = newnode; printf("added \n"); return; } // The list is not empty but attempting to // add the element in the head's position newnode->next = head; head->prev = newnode; head = newnode; printf("added \n"); return; } // Adding just after the tail node.. ie. when // nth == len+1 if (nth == l+1) { tail->next = newnode; newnode->prev = tail; tail = newnode; printf("added \n"); return; } // All the other cases --nth; while (--nth) { cur = cur->next; } newnode->prev = cur; newnode->next = cur->next; cur->next->prev = newnode; cur->next = newnode; printf("added \n"); return; }
void AppendFormat(const T *fmt, Args&&... args) { size_t l = length(); StringFormat(data + l, MAX_SIZE - l, fmt, args...); }
bool vcs_cart_slot_device::call_load() { if (m_cart) { UINT8 *ROM; UINT32 len; if (software_entry() != NULL) len = get_software_region_length("rom"); else len = length(); //printf("Size: 0x%X\n", len); // check that filesize is among the supported ones switch (len) { case 0x00800: case 0x01000: case 0x02000: case 0x028ff: case 0x02900: case 0x03000: case 0x04000: case 0x08000: case 0x10000: case 0x80000: break; default: seterror(IMAGE_ERROR_UNSUPPORTED, "Invalid rom file size" ); return IMAGE_INIT_FAIL; } m_cart->rom_alloc(len, tag()); ROM = m_cart->get_rom_base(); if (software_entry() != NULL) { const char *pcb_name; bool has_ram = get_software_region("ram") ? TRUE : FALSE; memcpy(ROM, get_software_region("rom"), len); if ((pcb_name = get_feature("slot")) != NULL) m_type = vcs_get_pcb_id(pcb_name); else { // identify type based on size switch (len) { case 0x800: m_type = A26_2K; break; case 0x1000: m_type = A26_4K; break; case 0x2000: m_type = A26_F8; break; case 0x28ff: case 0x2900: m_type = A26_DPC; break; case 0x3000: m_type = A26_FA; break; case 0x4000: m_type = A26_F6; break; case 0x8000: m_type = A26_F4; break; case 0x10000: m_type = A26_32IN1; break; case 0x80000: m_type = A26_3F; break; default: m_type = A26_4K; printf("Unrecognized cart type!\n"); break; } } if (has_ram) m_cart->ram_alloc(get_software_region_length("ram")); } else { fread(ROM, len); m_type = identify_cart_type(ROM, len); // check for Special Chip (128bytes of RAM) if (len == 0x2000 || len == 0x4000 || len == 0x8000) if (detect_super_chip(ROM, len)) { m_cart->ram_alloc(0x80); //printf("Super Chip detected!\n"); } // Super chip games: // dig dig, crystal castles, millipede, stargate, defender ii, jr. Pac Man, // desert falcon, dark chambers, super football, sprintmaster, fatal run, // off the wall, shooting arcade, secret quest, radar lock, save mary, klax // add CBS RAM+ (256bytes of RAM) if (m_type == A26_FA) m_cart->ram_alloc(0x100); // add M Network RAM else if (m_type == A26_E7) m_cart->ram_alloc(0x800); // add Commavid RAM else if (m_type == A26_CV) m_cart->ram_alloc(0x400); // add Starpath Superchager RAM else if (m_type == A26_SS) m_cart->ram_alloc(0x1800); // add Boulder Dash RAM else if (m_type == A26_3E) m_cart->ram_alloc(0x8000); } //printf("Type: %s\n", vcs_get_slot(m_type)); // pass a pointer to the now allocated ROM for the DPC chip if (m_type == A26_DPC) m_cart->setup_addon_ptr((UINT8 *)m_cart->get_rom_base() + 0x2000); return IMAGE_INIT_PASS; } return IMAGE_INIT_PASS; }
int CharacterData::maxCharacterOffset() const { return static_cast<int>(length()); }