int get_centroid(leveldb::DB* work_db, const leveldb::Slice& key, int K) {
  std::string str;
  auto keystr = get_centroid_prefix(-1, K) + key.ToString();
  auto status = work_db->Get({}, keystr, &str);
  if (status.IsNotFound()) return -1;
  CHECK_OK(status);
  return std::stoi(str);
}
示例#2
0
        void remove( const Key& k, bool sync = false )
        { try {
           FC_ASSERT( is_open(), "Database is not open!" );

           ldb::Slice ks( (char*)&k, sizeof(k) );
           auto status = _db->Delete( sync ? _sync_options : _write_options, ks );
           if( status.IsNotFound() )
           {
             FC_THROW_EXCEPTION( fc::key_not_found_exception, "unable to find key ${key}", ("key",k) );
           }
           if( !status.ok() )
           {
               FC_THROW_EXCEPTION( level_pod_map_failure, "database error: ${msg}", ("msg", status.ToString() ) );
           }
        } FC_RETHROW_EXCEPTIONS( warn, "error removing ${key}", ("key",k) ); }
bool
persistence_leveldb::is_available (map_coordinates xy)
{
    uint32_t key[3];
    key[0] = data_type::cnk_height;
    key[1] = xy.x;
    key[2] = xy.y;

    leveldb::Slice db_key (reinterpret_cast<const char*>(key), sizeof(key));
    std::string result;

    auto rc (db_->Get(leveldb::ReadOptions(), db_key, &result));

    return !rc.IsNotFound();
}
        void remove( const Key& k, bool sync = false )
        { try {
           FC_ASSERT( is_open(), "Database is not open!" );

           std::vector<char> kslice = fc::raw::pack( k );
           ldb::Slice ks( kslice.data(), kslice.size() );
           auto status = _db->Delete( ldb::WriteOptions(), ks );
           if( status.IsNotFound() )
           {
             FC_THROW_EXCEPTION( fc::key_not_found_exception, "unable to find key ${key}", ("key",k) );
           }
           if( !status.ok() )
           {
               FC_THROW_EXCEPTION( db_exception, "database error: ${msg}", ("msg", status.ToString() ) );
           }
        } FC_RETHROW_EXCEPTIONS( warn, "error removing ${key}", ("key",k) ); }
bool
persistence_leveldb::is_available (data_type type, chunk_coordinates xyz)
{
    uint32_t key[4];
    key[0] = type;
    key[1] = xyz.x;
    key[2] = xyz.y;
    key[3] = xyz.z;

    leveldb::Slice db_key (reinterpret_cast<const char*>(key), sizeof(key));
    std::string result;

    auto rc (db_->Get(leveldb::ReadOptions(), db_key, &result));

    return !rc.IsNotFound();
}
        void remove( const Key& k )
        {
          try
          {
            ldb::Slice ks( (char*)&k, sizeof(k) );
            auto status = _db->Delete( ldb::WriteOptions(), ks );

            if( status.IsNotFound() )
            {
              FC_THROW_EXCEPTION( key_not_found_exception, "unable to find key ${key}", ("key",k) );
            }
            if( !status.ok() )
            {
                FC_THROW_EXCEPTION( exception, "database error: ${msg}", ("msg", status.ToString() ) );
            }
          } FC_RETHROW_EXCEPTIONS( warn, "error removing ${key}", ("key",k) );
        }
示例#7
0
        Value fetch( const Key& key )
        { try {
           FC_ASSERT( is_open(), "Database is not open!" );

           ldb::Slice key_slice( (char*)&key, sizeof(key) );
           std::string value;
           auto status = _db->Get( _read_options, key_slice, &value );
           if( status.IsNotFound() )
           {
             FC_THROW_EXCEPTION( fc::key_not_found_exception, "unable to find key ${key}", ("key",key) );
           }
           if( !status.ok() )
           {
               FC_THROW_EXCEPTION( level_pod_map_failure, "database error: ${msg}", ("msg", status.ToString() ) );
           }
           fc::datastream<const char*> datastream(value.c_str(), value.size());
           Value tmp;
           fc::raw::unpack(datastream, tmp);
           return tmp;
        } FC_RETHROW_EXCEPTIONS( warn, "error fetching key ${key}", ("key",key) ); }
 Value fetch( const Key& key )
 {
   try {
      ldb::Slice key_slice( (char*)&key, sizeof(key) );
      std::string value;
      auto status = _db->Get( ldb::ReadOptions(), key_slice, &value );
      if( status.IsNotFound() )
      {
        FC_THROW_EXCEPTION( key_not_found_exception, "unable to find key ${key}", ("key",key) );
      }
      if( !status.ok() )
      {
          FC_THROW_EXCEPTION( exception, "database error: ${msg}", ("msg", status.ToString() ) );
      }
      fc::datastream<const char*> datastream(value.c_str(), value.size());
      Value tmp;
      fc::raw::unpack(datastream, tmp);
      return tmp;
   } FC_RETHROW_EXCEPTIONS( warn, "error fetching key ${key}", ("key",key) );
 }
        Value fetch( const Key& k )
        { try {
           FC_ASSERT( is_open(), "Database is not open!" );

           std::vector<char> kslice = fc::raw::pack( k );
           ldb::Slice ks( kslice.data(), kslice.size() );
           std::string value;
           auto status = _db->Get( ldb::ReadOptions(), ks, &value );
           if( status.IsNotFound() )
           {
             FC_THROW_EXCEPTION( fc::key_not_found_exception, "unable to find key ${key}", ("key",k) );
           }
           if( !status.ok() )
           {
               FC_THROW_EXCEPTION( db_exception, "database error: ${msg}", ("msg", status.ToString() ) );
           }
           fc::datastream<const char*> ds(value.c_str(), value.size());
           Value tmp;
           fc::raw::unpack(ds, tmp);
           return tmp;
        } FC_RETHROW_EXCEPTIONS( warn, "error fetching key ${key}", ("key",k) ); }