bool SRA_StatisticsNextPath ( const SRA_Statistics * self, ctx_t ctx, const char * path, const char** next ) { FUNC_ENTRY ( ctx, rcSRA, rcDatabase, rcAccessing ); const DictionaryEntry * node = NULL; assert ( self ); if ( path == NULL ) INTERNAL_ERROR ( xcParamNull, "path is NULL" ); else if ( path[0] == 0 ) { node = ( const DictionaryEntry * ) BSTreeFirst ( & self -> dictionary ); } else { node = ( const DictionaryEntry * ) BSTreeFind ( & self -> dictionary, ( const void * ) path, DictionaryEntryFind ); if ( node == NULL ) { INTERNAL_ERROR ( xcUnexpected, "dictionary item '%s' is not found", path ); } else { node = ( const DictionaryEntry * ) BSTNodeNext ( & node -> dad ); } } if ( node == NULL ) { *next = NULL; return false; } *next = node -> path; return true; }
static reference_region * find_reference_region_len( BSTree * regions, const char * name, size_t len ) { frrl ctx; ctx.name = name; ctx.len = len; return ( reference_region * ) BSTreeFind ( regions, &ctx, reference_vs_frr_wrapper ); }
static void count_indel_fragment( BSTree * fragments, const INSDC_4na_bin *bases, uint32_t len ) { find_fragment_ctx fctx; fctx.bases = malloc( len ); if ( fctx.bases != NULL ) { indel_fragment * fragment; uint32_t i; fctx.len = len; for ( i = 0; i < len; ++i ) ( ( char * )fctx.bases )[ i ] = _4na_to_ascii( bases[ i ], false ); fragment = ( indel_fragment * ) BSTreeFind ( fragments, &fctx, cmp_fragment_vs_find_ctx ); if ( fragment == NULL ) { fragment = make_indel_fragment( fctx.bases, len ); if ( fragment != NULL ) { rc_t rc = BSTreeInsert ( fragments, ( BSTNode * )fragment, cmp_fragment_vs_fragment ); if ( rc != 0 ) free_indel_fragment( ( BSTNode * )fragment, NULL ); } } else fragment->count++; free( ( void * ) fctx.bases ); } }
static rc_t KNSProxiesAddHttpProxyPath ( KNSProxies * self, const char * proxy, size_t proxy_size, uint16_t proxy_port ) { const String * proxy_host = NULL; rc_t rc = 0; HttpProxy * new_proxy = NULL; BSTItem * node = NULL; HttpProxy add = { proxy_host, proxy_port, 0 }; assert ( self ); if ( proxy == NULL ) return 0; if ( rc == 0 ) { String tmp; StringInit ( & tmp, proxy, proxy_size, string_len ( proxy, proxy_size ) ); rc = StringCopy ( & proxy_host, & tmp ); if ( rc == 0 ) add . proxy_host = proxy_host; else return rc; } if ( BSTreeFind ( & self -> proxie_tree, & add, BSTItemCmp ) != NULL ) { DBGMSG ( DBG_KNS, DBG_FLAG ( DBG_KNS_PROXY ), ( "Ignored duplicate proxy '%S:%d'\n", proxy_host, proxy_port ) ); free ( ( void * ) proxy_host ); return 0; } new_proxy = calloc ( 1, sizeof * new_proxy ); if ( new_proxy == NULL ) return RC ( rcNS, rcMgr, rcAllocating, rcMemory, rcExhausted ); new_proxy -> proxy_host = proxy_host; new_proxy -> proxy_port = proxy_port; node = calloc ( 1, sizeof * node ); if ( node == NULL ) { free ( new_proxy ); return RC ( rcNS, rcMgr, rcAllocating, rcMemory, rcExhausted ); } node -> proxy = new_proxy; rc = BSTreeInsert ( & self -> proxie_tree, ( BSTNode * ) node, BSTreeSort ); DBGMSG ( DBG_KNS, DBG_FLAG ( DBG_KNS_PROXY ), ( "Added proxy '%S:%d'\n", proxy_host, proxy_port ) ); if ( ! self -> http_proxy_enabled ) self -> http_proxy_enabled = ( proxy_host != NULL ); return rc; }
rc_t get_ref_exclude( ref_exclude *exclude, const String * name, int32_t ref_offset, uint32_t ref_len, uint8_t *exclude_vector, uint32_t *active ) { rc_t rc = 0; ref_node *node = NULL; /* look if we already have a node with the given name */ trans_node *t_node = ( trans_node * )BSTreeFind ( &exclude->translations, name, trans_node_find ); if ( t_node != NULL ) { rc = find_or_make_by_name( exclude, &t_node->translation, &node ); } else { rc = find_or_make_by_name( exclude, name, &node ); } if ( rc == 0 && node->valid ) { /* read the necessary row(s) and fill it into the exclude_vector */ rc = read_from_ref_node( node, ref_offset, ref_len, exclude_vector, active ); if ( rc == 0 ) { node->active_positions += *active; } } return rc; }
int main(int argc, char *argv[]) { BSTree T; int i, n, nvals, v[MAXVALS]; // Build tree from values in stdin T = newBSTree(); nvals = 0; while (nvals < MAXVALS && scanf("%d",&n) == 1) { v[nvals++] = n; T = BSTreeInsert(T,n); } // Display information about constructed tree printf("Tree:\n");showBSTree(T); printf("\n#nodes = %d, ",BSTreeNumNodes(T)); printf("#leaves = %d\n",BSTreeNumLeaves(T)); printf("Infix : "); BSTreeInfix(T); printf("\n"); printf("Prefix : "); BSTreePrefix(T); printf("\n"); printf("Postfix: "); BSTreePostfix(T); printf("\n"); printf("ByLevel: "); BSTreeLevelOrder(T); printf("\n"); if (argc >= 2) { FILE *out = fopen(argv[1], "w"); if (out) { BSTreeDot(T, out); fclose(out); } else { perror("fopen"); } } // Check correctness of tree // assume no duplicates => each value produces a node assert(nvals == BSTreeNumNodes(T)); // every inserted value can be found for (i = 0; i < nvals; i++) assert(BSTreeFind(T,v[i]) != 0); // (hopefully) non-existent value cannot be found assert(BSTreeFind(T,-7654321) == 0); dropBSTree(T); return 0; }
uint64_t SRA_StatisticsGetAsU64 ( const SRA_Statistics * self, ctx_t ctx, const char * path ) { FUNC_ENTRY ( ctx, rcSRA, rcDatabase, rcAccessing ); assert ( self ); if ( path == NULL ) INTERNAL_ERROR ( xcParamNull, "path is NULL" ); else { DictionaryEntry * node = ( DictionaryEntry * ) BSTreeFind ( & self -> dictionary, ( const void * ) path, DictionaryEntryFind ); if ( node == NULL ) { INTERNAL_ERROR ( xcUnexpected, "dictionary item '%s' is not found", path ); } else { switch ( node -> type ) { case NGS_StatisticValueType_Int64: if ( node -> value . i64 < 0 ) { INTERNAL_ERROR ( xcUnexpected, "cannot convert dictionary item '%s' from in64_t to uint64_t", path ); } else { return ( uint64_t ) node -> value . i64; } break; case NGS_StatisticValueType_UInt64: return node -> value . i64; case NGS_StatisticValueType_Real: if ( node -> value . real < 0 || node -> value . real > ULLONG_MAX ) { INTERNAL_ERROR ( xcUnexpected, "cannot convert dictionary item '%s' from double to uint64_t", path ); } else { return ( uint64_t ) xtrunc ( node -> value . real ); } break; case NGS_StatisticValueType_String: return NGS_StringToU64 ( node -> value . str, ctx ); default : INTERNAL_ERROR ( xcUnexpected, "unexpected type %u for dictionary item '%s'", node -> type, path ); break; } } } return 0; }
NGS_String* SRA_StatisticsGetAsString ( const SRA_Statistics * self, ctx_t ctx, const char * path ) { FUNC_ENTRY ( ctx, rcSRA, rcDatabase, rcAccessing ); assert ( self ); if ( path == NULL ) INTERNAL_ERROR ( xcParamNull, "path is NULL" ); else { DictionaryEntry * node = ( DictionaryEntry * ) BSTreeFind ( & self -> dictionary, ( const void * ) path, DictionaryEntryFind ); if ( node == NULL ) { INTERNAL_ERROR ( xcUnexpected, "dictionary item '%s' is not found", path ); } else { switch ( node -> type ) { case NGS_StatisticValueType_UInt64: { char buf[1024]; size_t num_writ; string_printf ( buf, sizeof(buf), &num_writ, "%lu", node -> value . u64 ); return NGS_StringMakeCopy ( ctx, buf, num_writ ); } break; case NGS_StatisticValueType_Int64: { char buf[1024]; size_t num_writ; string_printf ( buf, sizeof(buf), &num_writ, "%li", node -> value . i64 ); return NGS_StringMakeCopy ( ctx, buf, num_writ ); } case NGS_StatisticValueType_Real: { char buf[1024]; size_t num_writ; string_printf ( buf, sizeof(buf), &num_writ, "%f", node -> value . real ); return NGS_StringMakeCopy ( ctx, buf, num_writ ); } case NGS_StatisticValueType_String: return NGS_StringDuplicate ( node -> value . str, ctx ); default : INTERNAL_ERROR ( xcUnexpected, "unexpected type %u for dictionary item '%s'", node -> type, path ); break; } } } return NULL; }
void InvertedIndex(void){ listOfCollection = CollectionToList(); N = Length(listOfCollection); int L = LengthForMalloc(listOfCollection); ptr = malloc(sizeof(BSTree) * L); for(int i = 0; i < N; i++) { url = valueReturn(listOfCollection,i); urltx = strcat(url,txt); f = fopen(urltx, "r"); sizefile = fopen(urltx, "r"); size = sizeOfFile(sizefile); Q = getBSTree(f,size); ptr[i]= Q; fclose(f); fclose(sizefile); } WithoutTxt = CollectionToList(); AllWords = AllWordsToList(N,listOfCollection,WithoutTxt); int numberofWords = Length(AllWords); FILE *Inverted = fopen("Inverted.txt","w"); for (int test = 0; test <= numberofWords; test++){ searchTerm= valueReturn(AllWords, test); fprintf(Inverted, "%s",searchTerm); for(int iterator = 0; iterator <= N; iterator++){ // Set the search term as the term returned by ALL found = BSTreeFind(ptr[iterator],searchTerm); if(found == 1){ URLname = valueReturn(WithoutTxt, iterator); fprintf(Inverted," %s", URLname); } else{ // Do nothing } } fprintf(Inverted,"\n"); } }
/* you cannot addref to this dir object cause it's created on stack silently */ static rc_t CC DirVisitor(const KDirectory *dir, uint32_t type, const char *name, void *data) { rc_t rc = 0; DirVisit_Data* d = (DirVisit_Data*)data; if( (type & ~kptAlias) == kptFile ) { if (strcmp(&name[strlen(name) - 4], ".tsv") == 0 || strcmp(&name[strlen(name) - 8], ".tsv.bz2") == 0 || strcmp(&name[strlen(name) - 7], ".tsv.gz") == 0) { char buf[4096]; const CGLoaderFile* file; FGroupKey key; if( (rc = KDirectoryResolvePath(dir, true, buf, sizeof(buf), name)) == 0 && (rc = CGLoaderFile_Make(&file, d->dir, buf, NULL, !d->param->no_read_ahead)) == 0 && (rc = FGroupKey_Make(&key, file, d->param)) == 0 ) { FGroupMAP* found = (FGroupMAP*)BSTreeFind(d->tree, &key, FGroupMAP_Cmp); DEBUG_MSG(5, ("file %s recognized\n", name)); if( found != NULL ) { rc = FGroupMAP_Set(found, file); } else { FGroupMAP* x = calloc(1, sizeof(*x)); if( x == NULL ) { rc = RC(rcExe, rcFile, rcInserting, rcMemory, rcExhausted); } else { memcpy(&x->key, &key, sizeof(key)); if( (rc = FGroupMAP_Set(x, file)) == 0 ) { rc = BSTreeInsertUnique(d->tree, &x->dad, NULL, FGroupMAP_Sort); } } } } else if( GetRCObject(rc) == rcItem && GetRCState(rc) == rcIgnored ) { DEBUG_MSG(5, ("file %s ignored\n", name)); rc = CGLoaderFile_Release(file, true); file = NULL; } if( rc != 0 && file != NULL ) { CGLoaderFile_LOG(file, klogErr, rc, NULL, NULL); CGLoaderFile_Release(file, true); } } else if( strcmp(&name[strlen(name) - 4], ".tar") == 0 ) { const KDirectory* tmp = d->dir; if( (rc = KDirectoryOpenArcDirRead(dir, &d->dir, true, name, tocKFile, KArcParseTAR, NULL, NULL)) == 0 ) { rc = KDirectoryVisit(d->dir, true, DirVisitor, d, "."); KDirectoryRelease(d->dir); } d->dir = tmp; } } return rc; }
const struct _TNode * CC _TeleportLookup ( const char * Type ) { if ( _sTeleportInited == true ) { return ( const struct _TNode * ) BSTreeFind ( ( struct BSTree * ) & _sTeleport, Type, _TeleportLookupCallback ); } return NULL; } /* _TeleportLookup () */
static rc_t XmlMetaInitMemser(BSTree* tr, const KXMLNode* node, const char* path, const char* member_name) { rc_t rc = 0; MetaMember* member = (MetaMember*)BSTreeFind(tr, member_name, MetaMemberCmp); if (member) { rc = RC(rcExe, rcMetadata, rcReading, rcAttr, rcDuplicate); PLOGERR(klogErr, ( klogErr, rc, "Member/@member_name='$(name)'", "name=%s", member_name)); } else { member = calloc(1, sizeof(*member)); if (member == NULL) { rc = RC(rcExe, rcStorage, rcAllocating, rcMemory, rcExhausted); } if (rc == 0) { member->member_name = strdup(member_name); if (member == NULL) { rc = RC(rcExe, rcStorage, rcAllocating, rcMemory, rcExhausted); } } if (rc == 0) { member->meta = calloc(1, sizeof(*member->meta)); if (member->meta == NULL) { rc = RC(rcExe, rcStorage, rcAllocating, rcMemory, rcExhausted); } } if (rc == 0) { rc = ParseSraMetaNode(node, path, member_name, member->meta); } if (rc) { if (member) { FREE(member->member_name); FREE(member->meta); FREE(member); } } else { BSTreeInsert(tr, (BSTNode*)member, MetaMemberSort); } } return rc; }
rc_t make_column_typelist ( const BSTree *columns, const char *col, uint32_t *dflt_idx, KNamelist **typedecls ) { VNamelist *list; rc_t rc = VNamelistMake ( & list, 8 ); if ( rc == 0 ) { uint32_t idx; const VColumnRef *first; String col_name; StringInitCString ( & col_name, col ); first = ( const VColumnRef* ) BSTreeFind ( columns, & col_name, VColumnRefCmpString ); if ( first != NULL ) { const VColumnRef *cref = ( const VColumnRef* ) BSTNodePrev ( & first -> n ); while ( cref != NULL && StringEqual ( & first -> name, & cref -> name ) ) { first = cref; cref = ( const VColumnRef* ) BSTNodePrev ( & cref -> n ); } for ( cref = first, idx = 0; ; ++ idx ) { rc = VNamelistAppend ( list, cref -> typedecl ); if ( rc != 0 ) break; if ( cref -> dflt ) * dflt_idx = idx; cref = ( const VColumnRef* ) BSTNodeNext ( & cref -> n ); if ( cref == NULL || ! StringEqual ( & first -> name, & cref -> name ) ) break; } } if ( rc == 0 ) rc = VNamelistToNamelist ( list, typedecls ); VNamelistRelease ( list ); } return rc; }
rc_t KU64IndexDelete_v3(KU64Index_v3* self, uint64_t key) { KU64Index_Node node; BSTNode* n = NULL; self->rc = 0; node.key = key; n = BSTreeFind(&self->tree, &node, KU64Index_Cmp4Delete); if( n != NULL ) { if( !BSTreeUnlink(&self->tree, n) ) { self->rc = RC(rcDB, rcIndex, rcDestroying, rcId, rcCorrupt); } } else { self->rc = RC(rcDB, rcIndex, rcDestroying, rcId, rcNotFound); } return self->rc; }
const struct XFSOwpEntry * CC _OWPEntryFind ( const struct XFSOwp * self, const char * Key ) { struct XFSOwpEntry * Entry; Entry = NULL; if ( self != NULL && Key != NULL ) { Entry = ( struct XFSOwpEntry * ) BSTreeFind ( ( BSTree * )self, Key, _OWPEntryCmp ); } return Entry; } /* _OWPEntryFind () */
rc_t KeyRingDataAddProject(KeyRingData* data, const String* name, const String* download_ticket, const String* encryption_key) { rc_t rc = 0; Project* p; p = (Project*)BSTreeFind(&data->projects, name, FindProject); if (p != NULL) { bool rewrite = false; String* dl = NULL; String* enc = NULL; if (StringCompare(p->download_ticket, download_ticket) != 0) { dl = p->download_ticket; rc = StringCopy((const String**)&p->download_ticket, download_ticket); if (rc == 0) rewrite = true; else dl = NULL; } if (rc == 0 && StringCompare(p->encryption_key, encryption_key) != 0) { enc = p->encryption_key; rc = StringCopy((const String**)&p->encryption_key, encryption_key); if (rc == 0) rewrite = true; else enc = NULL; } if (rc == 0 && rewrite) { if (dl) StringWhack(dl); if (enc) StringWhack(enc); } } else /* insert new */ { rc = KeyRingDataInsertProject (&data->projects, data->next_projectId, name, download_ticket, encryption_key); if (rc == 0) ++data->next_projectId; } return rc; }
void skiplist_enter_ref( struct skiplist * list, const char * name ) { if ( list != NULL ) { if ( name == NULL ) list->current = NULL; else { struct skiplist_ref_node * cur_node = ( struct skiplist_ref_node * )BSTreeFind ( &( list->nodes ), name, pchar_vs_srn_cmp ); list->current = cur_node; if ( cur_node != NULL ) { cur_node->current_id = 0; cur_node->current_skip_range = VectorGet ( &( cur_node->skip_ranges ), 0 ); } } } }
double SRA_StatisticsGetAsDouble ( const SRA_Statistics * self, ctx_t ctx, const char * path ) { FUNC_ENTRY ( ctx, rcSRA, rcDatabase, rcAccessing ); assert ( self ); if ( path == NULL ) INTERNAL_ERROR ( xcParamNull, "path is NULL" ); else { DictionaryEntry * node = ( DictionaryEntry * ) BSTreeFind ( & self -> dictionary, ( const void * ) path, DictionaryEntryFind ); if ( node == NULL ) { INTERNAL_ERROR ( xcUnexpected, "dictionary item '%s' is not found", path ); } else { switch ( node -> type ) { case NGS_StatisticValueType_Int64: return ( double ) node -> value . i64; case NGS_StatisticValueType_UInt64: return ( double ) node -> value . u64; case NGS_StatisticValueType_Real: return node -> value . real; case NGS_StatisticValueType_String: return NGS_StringToReal ( node -> value . str, ctx ); break; default : INTERNAL_ERROR ( xcUnexpected, "unexpected type %u for dictionary item '%s'", node -> type, path ); break; } } } return 0; }
static ref_node * find_ref_node( ref_exclude *exclude, const String * s ) { BSTNode *node; if ( exclude->last_used_ref_node != NULL ) { ref_node * node = ( ref_node * )exclude->last_used_ref_node; if ( StringCompare ( s, node->name ) == 0 ) return node; } node = BSTreeFind ( &exclude->ref_nodes, s, ref_node_find ); if ( node == NULL ) return NULL; else { exclude->last_used_ref_node = node; return ( ref_node * ) node; } }
const struct __SidNode * _FindSidNoLock ( const char * Name ) { const struct __SidNode * RetVal; RetVal = NULL; if ( Name != NULL ) { RetVal = ( const struct __SidNode * ) BSTreeFind ( & _sSidStorage, Name, _SidStorageFindCallback ); if ( RetVal == NULL ) { _AddSidNoLock ( Name, ( struct __SidNode ** ) & RetVal ); } } return RetVal; } /* _FindSidNoLock () */
static rc_t cg_dump_row( cg_dump_opts * opts, cg_dump_ctx * cg_ctx, uint64_t row_id ) { uint32_t elem_bits, boff, sg_len; const char * sg; rc_t rc = VCursorCellDataDirect( cg_ctx->seq_cur, row_id, cg_ctx->seq_sg_idx, &elem_bits, (const void**)&sg, &boff, &sg_len ); if ( rc != 0 ) { (void)PLOGERR( klogErr, ( klogErr, rc, "cannot read spot-group in row #$(row_id)", "row_id=%lu", row_id ) ); } else { String spot_group; lane * sg_lane; StringInit( &spot_group, sg, sg_len, sg_len ); sg_lane = ( lane * )BSTreeFind ( &cg_ctx->lanes, &spot_group, String_lane_cmp ); if ( sg_lane == NULL ) { /* KOutMsg( "row %lu (%S) not found, create it\n", row_id, &spot_group ); */ rc = make_lane( opts, cg_ctx->lookup, cg_ctx->out_dir, &spot_group, &sg_lane ); if ( rc == 0 ) { rc = BSTreeInsert ( &cg_ctx->lanes, ( BSTNode * )sg_lane, lane_lane_cmp ); if ( rc != 0 ) { (void)LOGERR( klogErr, rc, "cannot insert new lane" ); whack_lane( sg_lane ); } } } else { /* KOutMsg( "row %lu (%S) found, use it\n", row_id, &spot_group ); */ } if ( rc == 0 ) { cg_dump_write_spot( opts, cg_ctx, row_id, sg_lane ); /* <================== */ } } return rc; }
static spotgrp * find_spotgroup( statistic *self, const char *src, const size_t len ) { String s; BSTNode *node; StringInit( &s, src, len, len ); if ( self->last_used_spotgroup != NULL ) { spotgrp * sg = ( spotgrp* )self->last_used_spotgroup; if ( StringCompare ( &s, sg->name ) == 0 ) return sg; } node = BSTreeFind ( &self->spotgroups, &s, spotgroup_find ); if ( node == NULL ) return NULL; else { self->last_used_spotgroup = node; return ( spotgrp *) node; } }
static bool pnamesUsePath (const char * path) { bool ret; STSMSG (4, ("Use path called %s", path)); STSMSG (4, ("Depth %u ", BSTreeDepth(&pnames, false) )); if (BSTreeDepth(&pnames, false) == 0) { /* PLOGMSG (klogDebug9, "pnamesUsePath use $(P) by default", PLOG_S(P), path); */ ret = true; } else { ret = ( BSTreeFind (&pnames, path, pnameFindCmp ) != NULL); /* if (ret) */ /* PLOGMSG (klogDebug9, "pnamesUsePath use $(P)", PLOG_S(P), path); */ /* else */ /* PLOGMSG (klogDebug9, "pnamesUsePath don't use $(P)", PLOG_S(P), path); */ } STSMSG (4, ("Use? %u ", ret)); return ret; }
static rc_t mark_type_sensitivity ( const BSTree *stype_tbl, const VSchema *schema, const VTypedecl *td, vtblcp_column_map *cm ) { const stype_id *node; /* simple case - look for exact matches */ if ( BSTreeFind ( stype_tbl, td, stype_id_cmp ) != NULL ) { cm -> sensitive = true; return 0; } /* exhaustive case - perform one by one ancestry test */ for ( node = ( const stype_id* ) BSTreeFirst ( stype_tbl ); node != NULL; node = ( const stype_id* ) BSTNodeNext ( & node -> n ) ) { cm -> redact_value = NULL; if ( td -> type_id > node -> type_id ) { VTypedecl cast; /* test for our type being a subtype */ if ( VTypedeclToType ( td, schema, node -> type_id, & cast, NULL ) ) { cm -> redact_value = node -> redact_value; cm -> sensitive = true; return 0; } } } /* doesn't appear to be sensitive */ cm -> sensitive = false; return 0; }
uint32_t SRA_StatisticsGetValueType ( const SRA_Statistics * self, ctx_t ctx, const char * path ) { FUNC_ENTRY ( ctx, rcSRA, rcDatabase, rcAccessing ); assert ( self ); if ( path == NULL ) INTERNAL_ERROR ( xcParamNull, "path is NULL" ); else { DictionaryEntry * node = ( DictionaryEntry * ) BSTreeFind ( & self -> dictionary, ( const void * ) path, DictionaryEntryFind ); if ( node == NULL ) { INTERNAL_ERROR ( xcUnexpected, "dictionary item '%s' is not found", path ); } else { return node -> type; } } return NGS_StatisticValueType_Undefined; }
const Project* KeyRingDataGetProject (const KeyRingData* data, const String* name) { return (const Project*)BSTreeFind(&data->projects, name, FindProject); }
const Object* KeyRingDataGetObject (const KeyRingData* data, const String* name) { return (const Object*)BSTreeFind(&data->objects, name, FindObject); }
rc_t KeyRingDataAddObject (KeyRingData* data, const String* name, const String* project, const String* display_name, uint64_t size, const String* checksum, const String* encryption_key) { rc_t rc = 0; Object* obj; obj = (Object*)BSTreeFind(&data->objects, name, FindObject); if (obj != NULL) { bool rewrite = false; String* proj = NULL; String* disp = NULL; String* csum = NULL; String* encr = NULL; if (StringCompare(obj->project, project) != 0) { proj = obj->project; rc = StringCopy((const String**)&obj->project, project); if (rc == 0) rewrite = true; else proj = NULL; } if (StringCompare(obj->display_name, display_name) != 0) { disp = obj->display_name; rc = StringCopy((const String**)&obj->display_name, display_name); if (rc == 0) rewrite = true; else disp = NULL; } if (size != obj->size) { obj->size = size; rewrite = true; } if (StringCompare(obj->checksum, checksum) != 0) { csum = obj->checksum; rc = StringCopy((const String**)&obj->checksum, checksum); if (rc == 0) rewrite = true; else csum = NULL; } if (StringCompare(obj->encryption_key, encryption_key) != 0) { encr = obj->encryption_key; rc = StringCopy((const String**)&obj->encryption_key, encryption_key); if (rc == 0) rewrite = true; else encr = NULL; } if (rc == 0 && rewrite) { if (proj) StringWhack(proj); if (disp) StringWhack(disp); if (csum) StringWhack(csum); if (encr) StringWhack(encr); } } else /* insert new */ { rc = KeyRingDataInsertObject(&data->objects, data->next_objectId, name, project, display_name, size, checksum, encryption_key); if (rc == 0) ++data->next_objectId; } return rc; }
/* function INSDC:coord:zero NCBI:align:ref_pos ( I64 ref_id, INSDC:coord:zero ref_start ); */ static rc_t CC align_ref_pos ( void *data, const VXformInfo *info, int64_t row_id, VRowResult *rslt, uint32_t argc, const VRowData argv[] ) { rc_t rc = 0; RefPos const *self = ( void const * )data; int64_t ref_row_id = 0; INSDC_coord_zero *ref_pos; unsigned const ploidy = ( unsigned const )argv[ REF_START ].u.data.elem_count; unsigned i; /* get start and length of reference segment */ int64_t const *ref_id = 0; INSDC_coord_zero const *ref_start; assert( argv[ REF_ID ].u.data.elem_bits == sizeof( *ref_id ) * 8 ); assert( argv[ REF_START ].u.data.elem_bits == sizeof( *ref_start ) * 8 ); ref_start = argv[ REF_START ].u.data.base; ref_start += argv[ REF_START ].u.data.first_elem; if ( self->curs != NULL ) { char const *name = NULL; uint32_t name_len; BSTRowRange *brr; ref_id = argv[ REF_ID ].u.data.base; ref_id += argv[ REF_ID ].u.data.first_elem; brr = ( BSTRowRange * )BSTreeFind( &self->tr_range, &ref_id[ 0 ], row_range_cmp ); if ( brr == NULL ) { RowRange *new_rr; SUB_DEBUG( ( "SUB.Rd in 'align-ref-pos.c' at #%lu\n", ref_id[ 0 ] ) ); rc = VCursorCellDataDirect( self->curs, ref_id[ 0 ], self->name_idx, NULL, (void const **)&name, NULL, &name_len ); if ( rc != 0 ) return rc; rc = VCursorParamsSet( ( struct VCursorParams const * )self->curs, "QUERY_SEQ_NAME", "%.*s", name_len, name ); if ( rc != 0 ) return rc; rc = VCursorCellDataDirect( self->curs, ref_id[ 0 ], self->name_range_idx, NULL, (void const **)&new_rr, NULL, NULL ); if ( rc != 0 ) return rc; brr = malloc( sizeof( *brr ) ); if ( brr == NULL ) { return RC( rcXF, rcFunction, rcConstructing, rcMemory, rcExhausted ); } else { memcpy( &brr->rr, new_rr, sizeof( *new_rr ) ); BSTreeInsert( ( BSTree* )&self->tr_range, ( BSTNode* )brr, row_range_sort ); } } ref_row_id = brr->rr.start_id; } rc = KDataBufferResize( rslt->data, ploidy ); if ( rc != 0 ) return rc; ref_pos = rslt->data->base; for ( i = 0; i != ploidy; ++i ) { ref_pos[ i ] = ref_start[ i ]; if ( self->curs != NULL ) { ref_pos[ i ] += ( INSDC_coord_zero )( ( ref_id[ 0 ] - ref_row_id ) * self->max_seq_len ); } } rslt->elem_count = ploidy; rslt->elem_bits = sizeof( ref_pos[ 0 ] ) * 8; return rc; }
static struct reference_region * find_reference_region( BSTree * regions, const char * name ) { return ( struct reference_region * ) BSTreeFind ( regions, name, reference_vs_pchar_wrapper ); }