|
| 1 | +/** |
| 2 | + * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) |
| 3 | + * |
| 4 | + * This file is part of libbitcoin. |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU Affero General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU Affero General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Affero General Public License |
| 17 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | +#ifndef LIBBITCOIN_DATABASE_TABLES_CACHES_DOUBLES_HPP |
| 20 | +#define LIBBITCOIN_DATABASE_TABLES_CACHES_DOUBLES_HPP |
| 21 | + |
| 22 | +#include <utility> |
| 23 | +#include <bitcoin/system.hpp> |
| 24 | +#include <bitcoin/database/define.hpp> |
| 25 | +#include <bitcoin/database/primitives/primitives.hpp> |
| 26 | +#include <bitcoin/database/tables/schema.hpp> |
| 27 | + |
| 28 | +namespace libbitcoin { |
| 29 | +namespace database { |
| 30 | +namespace table { |
| 31 | + |
| 32 | +// TODO: this table isn't actually mapped. |
| 33 | +struct doubles |
| 34 | + : public hash_map<schema::doubles> |
| 35 | +{ |
| 36 | + using hash_map<schema::doubles>::hashmap; |
| 37 | + using ix = linkage<schema::index>; |
| 38 | + |
| 39 | + // This supports only a single record (not too useful). |
| 40 | + struct record |
| 41 | + : public schema::doubles |
| 42 | + { |
| 43 | + inline bool from_data(reader& source) NOEXCEPT |
| 44 | + { |
| 45 | + hash = source.read_hash(); |
| 46 | + index = source.read_little_endian<ix::integer, ix::size>(); |
| 47 | + BC_ASSERT(!source || source.get_read_position() == count()); |
| 48 | + return source; |
| 49 | + } |
| 50 | + |
| 51 | + inline bool to_data(finalizer& sink) const NOEXCEPT |
| 52 | + { |
| 53 | + sink.write_bytes(hash); |
| 54 | + sink.write_little_endian<ix::integer, ix::size>(index); |
| 55 | + BC_ASSERT(!sink || sink.get_write_position() == count()); |
| 56 | + return sink; |
| 57 | + } |
| 58 | + |
| 59 | + inline bool operator==(const record& other) const NOEXCEPT |
| 60 | + { |
| 61 | + return hash == other.hash |
| 62 | + && index == other.index; |
| 63 | + } |
| 64 | + |
| 65 | + hash_digest hash{}; |
| 66 | + ix::integer index{}; |
| 67 | + }; |
| 68 | +}; |
| 69 | + |
| 70 | +} // namespace table |
| 71 | +} // namespace database |
| 72 | +} // namespace libbitcoin |
| 73 | + |
| 74 | +#endif |
0 commit comments