static Uint4 ToUint4(size_t size) { Uint4 ret = Uint4(size); if ( ret != size ) { NCBI_THROW(CLoaderException, eLoaderFailed, "Uint4 overflow"); } return ret; }
static SSpecParamsSet* s_FindNextParamsSet(const SSpecParamsSet* cur_set, const string& key, unsigned int& best_index) { unsigned int low = 1; unsigned int high = Uint4(cur_set->entries.size()); while (low < high) { unsigned int mid = (low + high) / 2; const SSpecParamsEntry& entry = cur_set->entries[mid]; int comp_res = s_CompareStrings(key, entry.key); if (comp_res == 0) { best_index = mid; return static_cast<SSpecParamsSet*>(entry.value.GetNCPointer()); } else if (comp_res > 0) low = mid + 1; else high = mid; } best_index = high; return NULL; }
CPoolOfThreads_ForServer::TItemHandle CPoolOfThreads_ForServer::GetHandle(void) { Uint4 q_num = Uint4(m_GetQueueNum.Add(1)) % m_MaxThreads; return m_Queues[q_num]->GetHandle(); }
void CPoolOfThreads_ForServer::AcceptRequest(const TRequest& req) { Uint4 q_num = Uint4(m_PutQueueNum.Add(1)) % m_MaxThreads; m_Queues[q_num]->Put(req); }
bool CSeqDBTaxInfo::GetTaxNames(Int4 tax_id, SSeqDBTaxInfo & info ) { static CTaxDBFileInfo t; if (t.IsMissingTaxInfo()) return false; Int4 low_index = 0; Int4 high_index = t.GetTaxidCount() - 1; const char * Data = t.GetDataPtr(); const CSeqDBTaxId* Index = t.GetIndexPtr(); Int4 low_taxid = Index[low_index ].GetTaxId(); Int4 high_taxid = Index[high_index].GetTaxId(); if((tax_id < low_taxid) || (tax_id > high_taxid)) return false; Int4 new_index = (low_index+high_index)/2; Int4 old_index = new_index; while(1) { Int4 curr_taxid = Index[new_index].GetTaxId(); if (tax_id < curr_taxid) { high_index = new_index; } else if (tax_id > curr_taxid){ low_index = new_index; } else { /* Got it ! */ break; } new_index = (low_index+high_index)/2; if (new_index == old_index) { if (tax_id > curr_taxid) { new_index++; } break; } old_index = new_index; } if (tax_id == Index[new_index].GetTaxId()) { info.taxid = tax_id; Uint4 begin_data(Index[new_index].GetOffset()); Uint4 end_data(0); if (new_index == high_index) { // Last index is special... end_data = Uint4(t.GetDataFileSize()); if (end_data < begin_data) { // Should not happen. ERR_POST( "Error: Offset error at end of taxdb file."); return false; } } else { end_data = (Index[new_index+1].GetOffset()); } const char * start_ptr = &Data[begin_data]; CSeqDB_Substring buffer(start_ptr, start_ptr + (end_data - begin_data)); CSeqDB_Substring sci, com, blast, king; bool rc1, rc2, rc3; rc1 = SeqDB_SplitString(buffer, sci, '\t'); rc2 = SeqDB_SplitString(buffer, com, '\t'); rc3 = SeqDB_SplitString(buffer, blast, '\t'); king = buffer; if (rc1 && rc2 && rc3 && buffer.Size()) { sci .GetString(info.scientific_name); com .GetString(info.common_name); blast .GetString(info.blast_name); king .GetString(info.s_kingdom); return true; } } return false; }