vector< T > compute_channel_means( const storage< T, L >& sto ) { // compute means vector< T > means( sto.channel_size() ); for ( index_t row = 0; row < sto.frame_size(); ++row ) for ( index_t col = 0; col < sto.channel_size(); ++col ) means[ col ] += sto( row, col ); for ( auto& m : means ) m /= sto.frame_size(); return means; }
void CommandQuit() { for (int i=0; i<numTables; i++) delete tables[i].gist; cout << "Goodbye.\n"; db.close(); exit(0); }
void storage::copy_from(const storage & ref) { U_32 pas = 0, delta; struct cellule *ptr = ref.first; first = last = NULL; try { while(ptr != NULL || pas > 0) { if(ptr != NULL) { delta = pas + ptr->size; ptr = ptr->next; } else delta = 0; if(delta < pas) // must make the allocation { struct cellule *debut, *fin; make_alloc(pas, debut, fin); fusionne(first, last, debut, fin, first, last); pas = delta; } else pas = delta; } } catch(Ememory & e) { detruit(first); first = last = NULL; throw; } iterator i_ref = ref.begin(); iterator i_new = begin(); while(i_ref != ref.end()) { *i_new = *i_ref; ++i_new; ++i_ref; } }
table< T > compute_covariance( const storage< T, L >& sto ) { auto nchannels = sto.channel_size(); auto nframes = sto.frame_size(); auto means = compute_channel_means( sto ); table< T, L > cv( nchannels, nchannels ); for ( size_t row = 0; row < nchannels; ++row ) { for ( size_t col = 0; col < nchannels; ++col ) { T v = T( 0 ); for ( index_t i = 0; i < sto.frame_size(); ++i ) v += ( sto( i, row ) - means[ row ] ) * ( sto( i, col ) - means[ col ] ); cv( row, col ) = v / nframes; } } return cv; }
bool core::archive::image_cache::append_to_file(storage& _storage, const images_map_t& _images) const { if (_images.empty()) return true; if (!open_storage_for_append(_storage)) return false; core::tools::auto_scope lb([&_storage] { _storage.close(); }); return serialize_block(_storage, _images); }
bool core::archive::image_cache::read_file(storage& _storage, images_map_t& _images) const { archive::storage_mode mode; mode.flags_.read_ = true; if (!_storage.open(mode)) return false; core::tools::auto_scope lb([&_storage]{ _storage.close(); }); core::tools::binary_stream stream; while (_storage.read_data_block(-1, stream)) { if (!unserialize_block(stream, _images)) return false; stream.reset(); } return _storage.get_last_error() == archive::error::end_of_file; }
int main() { cout << "** BTree: A B+-tree implementation based on Generalized Search Trees\n"; cout << "Type \"help\" for a list of commands.\n\n"; if (db.open()) { CommandPrompt(); yyparse(); return 0; } else { return 1; } }
int main() { cout << "** RTree: An R-Tree based on Generalized Search Trees\n"; cout << "Type \"help\" for a list of commands.\n\n"; if (db.open()) { CommandPrompt(); yyparse(); return 0; } else { return 1; } }
void CommandCreate(const char *method, const char *table) { if (numTables == MAX_TABLES) { cout << "This progam can only handle "<<MAX_TABLES<<" open tables.\n"; return; } if (GetTable(table) != NOT_FOUND) { cerr << "Table already open!\n"; return; } if (strcmp(method, "btree")) { cerr << "The only supported method is btree.\n"; return; } GiST *gist = new BT(db); GiST_POST_Root* root = (GiST_POST_Root*)db.get_root_object(); if (root == NULL) { root = new_in(db, GiST_POST_Root)(db); db.set_root_object(root); } gist->Create(table); if (!gist->IsOpen()) { cout << "Error opening table.\n"; delete gist; return; } cout << "Table " << table << " created as type " << method << ".\n"; tables[numTables].name = strdup(table); tables[numTables].gist = gist; numTables++; }
#include <catch.hpp> using namespace type_safe; namespace type_safe { template class basic_optional<compact_optional_storage<compact_bool_policy<bool>>>; template class basic_optional<compact_optional_storage<compact_integer_policy<int, -1>>>; template class basic_optional<compact_optional_storage<compact_floating_point_policy<float>>>; } // namespace type_safe TEST_CASE("compact_bool") { using storage = compact_optional_storage<compact_bool_policy<bool>>; storage s; REQUIRE(!s.has_value()); s.create_value(true); REQUIRE(s.has_value()); REQUIRE(s.get_value() == true); s.destroy_value(); REQUIRE(!s.has_value()); s.create_value(false); REQUIRE(s.has_value()); REQUIRE(s.get_value() == false); } TEST_CASE("compact_integer")
static void destruct(storage & _storage) noexcept { _storage.destruct(in_place< type >); }