Files

64 lines
1.8 KiB
C++
Raw Permalink Normal View History

2019-04-01 18:34:39 +02:00
/*
* This file is part of the Flowee project
2022-08-20 19:18:34 +02:00
* Copyright (C) 2019-2022 Tom Zander <tom@flowee.org>
2019-04-01 18:34:39 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef HASHSTORAGE_H
#define HASHSTORAGE_H
#include <uint256.h>
#include <boost/filesystem.hpp>
struct HashIndexPoint
{
int db = -1;
int row = -1;
};
inline bool operator==(const HashIndexPoint &a, const HashIndexPoint &b)
{
2019-04-03 18:55:33 +02:00
return a.db == b.db && a.row == b.row;
2019-04-01 18:34:39 +02:00
}
class HashStoragePrivate;
2019-04-05 13:50:41 +02:00
/// A fast lookup storage of hashes.
2019-04-01 18:34:39 +02:00
class HashStorage
{
public:
HashStorage(const boost::filesystem::path &basedir);
~HashStorage();
2019-04-05 13:50:41 +02:00
/// return the amount of databases
/// @see HashIndexPoint::db
int databaseCount() const;
/// Append the hash and return its unique point.
/// Please note behaviour is not defined if the same hash is appended twice.
HashIndexPoint append(const uint256 &hash);
2019-04-05 13:50:41 +02:00
/// Find in the collection the hash by point. This is an expensive operation!
const uint256 &find(HashIndexPoint point) const;
2019-04-05 13:50:41 +02:00
/// return the point given to the hash.
HashIndexPoint lookup(const uint256 &hash) const;
2019-04-01 18:34:39 +02:00
2019-04-01 21:15:24 +02:00
/// Flush all caches and make lookup on-disk only
void finalize();
2019-04-01 18:34:39 +02:00
private:
HashStoragePrivate *d;
};
#endif