BitMap Storage::BuildBitmap(UINT maxLength) const { LIVE_ASSERT(maxLength > 0); if (IsEmpty()) return BitMap(); UINT minIndex = GetMinIndex(); UINT maxIndex = GetMaxIndex(); if ((minIndex == 0) && (maxIndex == 0)) return BitMap(); LIVE_ASSERT(minIndex > 0); LIVE_ASSERT(minIndex <= maxIndex); UINT length = maxIndex - minIndex + 1; LIMIT_MAX(length, maxLength); maxIndex = minIndex + length - 1; const PieceInfoCollection& pieceColl = m_dataPieces; PieceInfoCollection::const_iterator BeginItr = pieceColl.find(minIndex); PieceInfoCollection::const_iterator EndItr = pieceColl.upper_bound(maxIndex); BitMap bitmap(minIndex, length); //2.生成Bitmap for (PieceInfoCollection::const_iterator itr = BeginItr; itr != EndItr; itr++ ) { LIVE_ASSERT(bitmap.IsInRange(itr->first)); bitmap.SetBit(itr->first); } return bitmap; }
TC_Error_Code TCDS_Ascii_Harmonic::LoadData(const wxString &data_file_path) { if(m_IndexFile) IndexFileIO( IFF_CLOSE, 0 ); m_indexfile_name = data_file_path; TC_Error_Code error_return = init_index_file(); if(error_return != TC_NO_ERROR) return error_return; wxFileName f(data_file_path); m_harmfile_name = f.GetPath( wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME ); m_harmfile_name += f.GetName(); error_return = LoadHarmonicConstants(m_harmfile_name); // Mark the index entries individually with invariant harmonic constants unsigned int max_index = GetMaxIndex(); for(unsigned int i=0 ; i < max_index ; i++) { IDX_entry *pIDX = GetIndexEntry( i ); if(pIDX) { pIDX->num_nodes = num_nodes; pIDX->num_csts = num_csts; pIDX->num_epochs = num_epochs; pIDX->m_cst_speeds = m_cst_speeds; pIDX->m_cst_nodes = m_cst_nodes; pIDX->m_cst_epochs = m_cst_epochs; pIDX->first_year = m_first_year; pIDX->m_work_buffer = m_work_buffer; } } return error_return; }
BitMap Storage::BuildBitmap() const { if (m_dataPieces.empty()) return BitMap(); UINT minIndex = GetMinIndex(); UINT maxIndex = GetMaxIndex(); if ((minIndex == 0) && (maxIndex == 0)) return BitMap(); LIVE_ASSERT(minIndex > 0); LIVE_ASSERT(minIndex <= maxIndex); UINT length = maxIndex - minIndex + 1; const PieceInfoCollection& pieceColl = m_dataPieces; PieceInfoCollection::const_iterator BeginItr = pieceColl.find(minIndex); PieceInfoCollection::const_iterator EndItr = pieceColl.find(maxIndex); BitMap bitmap(minIndex, length); // for(int i = 0; i < length; i ++ ) // { // bitmap.SetBit(minIndex + i); // } //2.生成Bitmap for (PieceInfoCollection::const_iterator itr = BeginItr; itr != EndItr; itr++ ) { LIVE_ASSERT(bitmap.IsInRange(itr->first)); bitmap.SetBit(itr->first); } return bitmap; }
int CHARACTER_RANK::ValueToIndex (CHARACTER_RANK_VALUE val) { for(int i=0; i<(int)m_pItemDataVector->size(); i++) { if(val < (*m_pItemDataVector)[i].threshold) return i; } return GetMaxIndex(); }
size_t Storage::RemoveExpired(const StreamIndicator& baseIndicator, UINT minBufferTime) { UINT64 elapsedTime = baseIndicator.GetElapsedTime(); LIVE_ASSERT(elapsedTime <= INT_MAX); if (elapsedTime <= minBufferTime) { return 0; } elapsedTime -= minBufferTime; size_t deletedCount = 0; PieceInfoCollection::iterator iter = m_dataPieces.begin(); while (iter != m_dataPieces.end()) { if (m_dataPieces.size() <= 1) break; MediaDataPiecePtr piece = iter->second.GetPiece(); CheckDataPiece(piece); UINT pieceIndex = iter->first; // 可能删掉upperBound对应的piece //LIVE_ASSERT(pieceIndex < upperBound); // 如果upperBound以后一直没有数据,或者距离很远才遇到下一片,则可能会发生upperBound对应的片也过时的情况 if (pieceIndex >= baseIndicator.GetPieceIndex()) { // peer端的BaseIndex不一定是最小的,需要加以检查 LIVE_ASSERT( piece->GetTimeStamp() >= baseIndicator.GetTimeStamp() ); UINT64 elapsedTimeStamp = piece->GetTimeStamp() - baseIndicator.GetTimeStamp(); if (elapsedTimeStamp >= elapsedTime) { SOURCENEW_DEBUG("推进 MinIndex="<<GetMinIndex()<<" MaxIndex="<<GetMaxIndex()<<" 推进时间戳="<<elapsedTime); break; } } // piece过期,删除之 STREAMBUFFER_WARN("Storage::RemoveExpired: " << make_tuple(pieceIndex, baseIndicator.GetPieceIndex())); DoDelete(iter++); ++deletedCount; } while (m_dataPieces.size() > STORAGE_PIECE_LIMIT) { DoDelete(m_dataPieces.begin()); } //m_unfinishedDataPieces.RemoveOld(GetMinIndex()); return deletedCount; }
AccountOpResult Battlenet::AccountMgr::LinkWithGameAccount(std::string const& email, std::string const& gameAccountName) { uint32 bnetAccountId = GetId(email); if (!bnetAccountId) return AccountOpResult::AOR_NAME_NOT_EXIST; uint32 gameAccountId = GameAccountMgr::GetId(gameAccountName); if (!gameAccountId) return AccountOpResult::AOR_NAME_NOT_EXIST; if (GetIdByGameAccount(gameAccountId)) return AccountOpResult::AOR_ACCOUNT_BAD_LINK; PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_BNET_GAME_ACCOUNT_LINK); stmt->setUInt32(0, bnetAccountId); stmt->setUInt8(1, GetMaxIndex(bnetAccountId) + 1); stmt->setUInt32(2, gameAccountId); LoginDatabase.Execute(stmt); return AccountOpResult::AOR_OK; }
void SortEigenvalues (double *WR, double *WI, double *VR, int matDim, int eigenModesNumber, int verbosity) { int N, i, j, index; double WRcopy[6], WIcopy[6], VRcopy[36]; double **VV; int *MaxIndex; N=eigenModesNumber; MaxIndex = malloc(sizeof(*MaxIndex)*N); VV = malloc(sizeof(*VV)*N); for (i=0; i<N; i++) VV[i] = malloc(sizeof(**VV)*N); /*--- Finding biggest components of vectors... */ for (i=0; i<N; i++) { for (j=0; j<N; j++) { VV[i][j]=pow(VR[i*2*matDim+j*2],2)+pow(VR[i*2*matDim+j*2+1],2)+ pow(VR[(i*2+1)*matDim+j*2],2)+pow(VR[(i*2+1)*matDim+j*2+1],2); } } for (i=0; i<N; i++) { MaxIndex[i]=GetMaxIndex(VV[i], N); } /*--- Copying arrays... */ for (i=0; i<matDim; i++) { WRcopy[i]=WR[i]; WIcopy[i]=WI[i]; for (j=0; j<matDim; j++) { VRcopy[i*matDim+j]=VR[i*matDim+j]; } } /*--- Copying back according to MaxIndex... */ for (i=0; i<N; i++) { index=MaxIndex[i]; WR[i*2]= WRcopy[index*2]; WR[i*2+1]=WRcopy[index*2+1]; WI[i*2]= WIcopy[index*2]; WI[i*2+1]=WIcopy[index*2+1]; for (j=0; j<matDim; j++) { VR[i*2*matDim+j]= VRcopy[index*2*matDim+j]; VR[(i*2+1)*matDim+j]=VRcopy[(index*2+1)*matDim+j]; } } if (verbosity > 0) { printf("Eigenvalues after sorting:\n"); for(i=0; i<matDim; i++) { printf("%d: %9.6f + i* %10.6f\n",i,WR[i],WI[i]); } } if (verbosity > 1) { printf("Vectors after sorting:\n"); MatrixPrintout((double*)&VR[0], &matDim, &matDim, 1); } free(MaxIndex); for (i=0; i<N; i++) free(VV[i]); free(VV); }
void Storage::ViewStreamBuffer() const { VIEW_INFO("Storage::ViewStreamBuffer - LocalBitmap " << GetMinIndex() << " " << GetMaxIndex() << " " << BuildBitmap().GetResourceString() << " End"); }
UINT Storage::GetBufferSize() const { if (m_dataPieces.empty()) return 0; return GetMaxIndex() - GetMinIndex() + 1; }
TC_Error_Code TCDS_Binary_Harmonic::LoadData(const wxString &data_file_path) { if(!open_tide_db (data_file_path.mb_str())) return TC_TCD_FILE_CORRUPT; //Build the tables of constituent data DB_HEADER_PUBLIC hdr = get_tide_db_header (); source_ident = wxString( hdr.version, wxConvUTF8 ); num_csts = hdr.constituents; if(0 == num_csts) return TC_GENERIC_ERROR; num_nodes = hdr.number_of_years; if(0 == num_nodes) return TC_GENERIC_ERROR; // Allocate a working buffer m_work_buffer = (double *) malloc (num_csts * sizeof (double)); // Constituent speeds m_cst_speeds = (double *) malloc (num_csts * sizeof (double)); for (int a=0; a<num_csts; a++) { m_cst_speeds[a] = get_speed (a); m_cst_speeds[a] *= M_PI / 648000; /* Convert to radians per second */ } // Equilibrium tables by year m_first_year = hdr.start_year; num_epochs = hdr.number_of_years; m_cst_epochs = (double **) malloc (num_csts * sizeof (double *)); for (int i=0; i<num_csts; i++) m_cst_epochs[i] = (double *) malloc (num_epochs * sizeof (double)); for (int i=0; i<num_csts; i++) { for (int year=0; year<num_epochs; year++) { m_cst_epochs[i][year] = get_equilibrium (i, year); m_cst_epochs[i][year] *= M_PI / 180.0; } } // Node factors m_cst_nodes = (double **) malloc (num_csts * sizeof (double *)); for (int a=0; a<num_csts; a++) m_cst_nodes[a] = (double *) malloc (num_nodes * sizeof (double)); for (int a=0; a<num_csts; a++) { for (int year=0; year<num_nodes; year++) m_cst_nodes[a][year] = get_node_factor (a, year); } // now load and create the index TIDE_RECORD *ptiderec = (TIDE_RECORD *)calloc(sizeof(TIDE_RECORD), 1); for(unsigned int i=0 ; i < hdr.number_of_records ; i++) { read_tide_record (i, ptiderec); num_IDX++; // Keep counting entries for harmonic file stuff IDX_entry *pIDX = new IDX_entry; pIDX->source_data_type = SOURCE_TYPE_BINARY_HARMONIC; pIDX->pDataSource = NULL; pIDX->Valid15 = 0; pIDX->pref_sta_data = NULL; // no reference data yet pIDX->IDX_Useable = 1; // but assume data is OK pIDX->IDX_tzname = NULL; pIDX->IDX_lon = ptiderec->header.longitude; pIDX->IDX_lat = ptiderec->header.latitude; const char *tz = get_tzfile (ptiderec->header.tzfile); change_time_zone ((char *)tz); if(tz_info) pIDX->IDX_time_zone = -tz_info->tzi.Bias; strncpy(pIDX->IDX_station_name, ptiderec->header.name, MAXNAMELEN); // if(strstr(ptiderec->header.name, "Beaufort") != NULL) // int yyp = 4; pIDX->IDX_flood_dir = ptiderec->max_direction; pIDX->IDX_ebb_dir = ptiderec->min_direction; if(REFERENCE_STATION == ptiderec->header.record_type) { // Establish Station Type wxString caplin(pIDX->IDX_station_name, wxConvUTF8); caplin.MakeUpper(); if(caplin.Contains(_T("CURRENT"))) pIDX->IDX_type = 'C'; else pIDX->IDX_type = 'T'; int t1 = ptiderec->zone_offset; double zone_offset = (double)(t1 / 100) + ((double)(t1 % 100))/60.; // pIDX->IDX_time_zone = t1a; pIDX->IDX_ht_time_off = pIDX->IDX_lt_time_off = 0; pIDX->IDX_ht_mpy = pIDX->IDX_lt_mpy = 1.0; pIDX->IDX_ht_off = pIDX->IDX_lt_off = 0.0; pIDX->IDX_ref_dbIndex = ptiderec->header.reference_station; // will be -1 // build a Station_Data class, and add to member array Station_Data *psd = new Station_Data; psd->amplitude = (double *)malloc(num_csts * sizeof(double)); psd->epoch = (double *)malloc(num_csts * sizeof(double)); psd->station_name = (char *)malloc(ONELINER_LENGTH); strncpy(psd->station_name, ptiderec->header.name, MAXNAMELEN); psd->station_type = pIDX->IDX_type; // Get meridian, which is seconds difference from UTC, not figuring DST, so that New York is always (-300 * 60) psd->meridian = -(tz_info->tzi.Bias * 60); psd->zone_offset = zone_offset; // Get units strncpy (psd->unit, get_level_units (ptiderec->level_units), 40 - 1); psd->unit[40 -1] = '\0'; psd->have_BOGUS = (findunit(psd->unit) != -1) && (known_units[findunit(psd->unit)].type == BOGUS); int unit_c; if (psd->have_BOGUS) unit_c = findunit("knots"); else unit_c = findunit(psd->unit); if(unit_c != -1) { strncpy (psd->units_conv, known_units[unit_c].name, sizeof(psd->units_conv)-1); strncpy (psd->units_abbrv, known_units[unit_c].abbrv, sizeof(psd->units_abbrv)-1); } else { strncpy (psd->units_conv, psd->unit, 40 - 1); psd->units_conv[40 - 1] = '\0'; strncpy (psd->units_abbrv, psd->unit, 20 - 1); psd->units_abbrv[20 - 1] = '\0'; } // Get constituents for (int a=0; a<num_csts; a++) { psd->amplitude[a] = ptiderec->amplitude[a]; psd->epoch[a] = ptiderec->epoch[a] * M_PI / 180.; } psd->DATUM = ptiderec->datum_offset; m_msd_array.Add(psd); // add it to the member array pIDX->pref_sta_data = psd; pIDX->IDX_ref_dbIndex = i; pIDX->have_offsets = 0; } else if(SUBORDINATE_STATION == ptiderec->header.record_type) { // Establish Station Type wxString caplin(pIDX->IDX_station_name, wxConvUTF8); caplin.MakeUpper(); if(caplin.Contains(_T("CURRENT"))) pIDX->IDX_type = 'c'; else pIDX->IDX_type = 't'; int t1 = ptiderec->max_time_add; double t1a = (double)(t1 / 100) + ((double)(t1 % 100))/60.; t1a *= 60; // Minutes pIDX->IDX_ht_time_off = t1a; pIDX->IDX_ht_mpy = ptiderec->max_level_multiply; if(0. == pIDX->IDX_ht_mpy) pIDX->IDX_ht_mpy = 1.0; pIDX->IDX_ht_off = ptiderec->max_level_add; t1 = ptiderec->min_time_add; t1a = (double)(t1 / 100) + ((double)(t1 % 100))/60.; t1a *= 60; // Minutes pIDX->IDX_lt_time_off = t1a; pIDX->IDX_lt_mpy = ptiderec->min_level_multiply; if(0. == pIDX->IDX_lt_mpy) pIDX->IDX_lt_mpy = 1.0; pIDX->IDX_lt_off = ptiderec->min_level_add; pIDX->IDX_ref_dbIndex = ptiderec->header.reference_station; // strncpy(pIDX->IDX_reference_name, ptiderec->header.name, MAXNAMELEN); if( pIDX->IDX_ht_time_off || pIDX->IDX_ht_off != 0.0 || pIDX->IDX_lt_off != 0.0 || pIDX->IDX_ht_mpy != 1.0 || pIDX->IDX_lt_mpy != 1.0) pIDX->have_offsets = 1; } m_IDX_array.Add(pIDX); } // Mark the index entries individually with invariant harmonic constants unsigned int max_index = GetMaxIndex(); for(unsigned int i=0 ; i < max_index ; i++) { IDX_entry *pIDX = GetIndexEntry( i ); if(pIDX) { pIDX->num_nodes = num_nodes; pIDX->num_csts = num_csts; pIDX->num_epochs = num_epochs; pIDX->m_cst_speeds = m_cst_speeds; pIDX->m_cst_nodes = m_cst_nodes; pIDX->m_cst_epochs = m_cst_epochs; pIDX->first_year = m_first_year; pIDX->m_work_buffer = m_work_buffer; } } free( ptiderec ); return TC_NO_ERROR; }