mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-28 11:18:17 -07:00
parser: split txid_to_txdata db
This commit is contained in:
@@ -38,7 +38,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ROOT_DB: usize = 0;
|
const ROOT_DB: usize = 0;
|
||||||
const PAGE_SIZE: u64 = 4096 * 256; // 1mo - Must be a multiplier of 4096
|
const PAGE_SIZE: u64 = 4096;
|
||||||
|
|
||||||
impl<Key, Value> Database<Key, Value>
|
impl<Key, Value> Database<Key, Value>
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ impl DerefMut for AddressIndexToAddressData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DB_MAX_SIZE: usize = 500_000;
|
pub const ADDRESS_INDEX_DB_MAX_SIZE: usize = 250_000;
|
||||||
|
|
||||||
impl AddressIndexToAddressData {
|
impl AddressIndexToAddressData {
|
||||||
pub fn unsafe_insert(&mut self, key: Key, value: Value) -> Option<Value> {
|
pub fn unsafe_insert(&mut self, key: Key, value: Value) -> Option<Value> {
|
||||||
@@ -74,8 +74,8 @@ impl AddressIndexToAddressData {
|
|||||||
self.entry(db_index).or_insert_with(|| {
|
self.entry(db_index).or_insert_with(|| {
|
||||||
let db_name = format!(
|
let db_name = format!(
|
||||||
"{}..{}",
|
"{}..{}",
|
||||||
db_index * DB_MAX_SIZE,
|
db_index * ADDRESS_INDEX_DB_MAX_SIZE,
|
||||||
(db_index + 1) * DB_MAX_SIZE
|
(db_index + 1) * ADDRESS_INDEX_DB_MAX_SIZE
|
||||||
);
|
);
|
||||||
|
|
||||||
Database::open(Self::folder(), &db_name).unwrap()
|
Database::open(Self::folder(), &db_name).unwrap()
|
||||||
@@ -120,7 +120,7 @@ impl AddressIndexToAddressData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn db_index(key: &Key) -> usize {
|
fn db_index(key: &Key) -> usize {
|
||||||
*key as usize / DB_MAX_SIZE
|
*key as usize / ADDRESS_INDEX_DB_MAX_SIZE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use rayon::prelude::*;
|
|||||||
|
|
||||||
use crate::structs::{Date, EmptyAddressData, Height};
|
use crate::structs::{Date, EmptyAddressData, Height};
|
||||||
|
|
||||||
use super::{AnyDatabaseGroup, Database as _Database, Metadata};
|
use super::{AnyDatabaseGroup, Database as _Database, Metadata, ADDRESS_INDEX_DB_MAX_SIZE};
|
||||||
|
|
||||||
type Key = u32;
|
type Key = u32;
|
||||||
type Value = EmptyAddressData;
|
type Value = EmptyAddressData;
|
||||||
@@ -36,8 +36,6 @@ impl DerefMut for AddressIndexToEmptyAddressData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DB_MAX_SIZE: usize = 500_000;
|
|
||||||
|
|
||||||
impl AddressIndexToEmptyAddressData {
|
impl AddressIndexToEmptyAddressData {
|
||||||
pub fn unsafe_insert(&mut self, key: Key, value: Value) -> Option<Value> {
|
pub fn unsafe_insert(&mut self, key: Key, value: Value) -> Option<Value> {
|
||||||
self.metadata.called_insert();
|
self.metadata.called_insert();
|
||||||
@@ -76,8 +74,8 @@ impl AddressIndexToEmptyAddressData {
|
|||||||
self.entry(db_index).or_insert_with(|| {
|
self.entry(db_index).or_insert_with(|| {
|
||||||
let db_name = format!(
|
let db_name = format!(
|
||||||
"{}..{}",
|
"{}..{}",
|
||||||
db_index * DB_MAX_SIZE,
|
db_index * ADDRESS_INDEX_DB_MAX_SIZE,
|
||||||
(db_index + 1) * DB_MAX_SIZE
|
(db_index + 1) * ADDRESS_INDEX_DB_MAX_SIZE
|
||||||
);
|
);
|
||||||
|
|
||||||
Database::open(Self::folder(), &db_name).unwrap()
|
Database::open(Self::folder(), &db_name).unwrap()
|
||||||
@@ -85,7 +83,7 @@ impl AddressIndexToEmptyAddressData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn db_index(key: &Key) -> usize {
|
fn db_index(key: &Key) -> usize {
|
||||||
*key as usize / DB_MAX_SIZE
|
*key as usize / ADDRESS_INDEX_DB_MAX_SIZE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ type Database = _Database<Key, Value>;
|
|||||||
pub struct TxidToTxData {
|
pub struct TxidToTxData {
|
||||||
pub metadata: Metadata,
|
pub metadata: Metadata,
|
||||||
|
|
||||||
map: BTreeMap<u8, Database>,
|
map: BTreeMap<u16, Database>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for TxidToTxData {
|
impl Deref for TxidToTxData {
|
||||||
type Target = BTreeMap<u8, Database>;
|
type Target = BTreeMap<u16, Database>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.map
|
&self.map
|
||||||
@@ -113,8 +113,8 @@ impl TxidToTxData {
|
|||||||
U8x31::from(&txid[1..])
|
U8x31::from(&txid[1..])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn db_index(txid: &Txid) -> u8 {
|
fn db_index(txid: &Txid) -> u16 {
|
||||||
txid[0]
|
((txid[0] as u16) << 4) + ((txid[1] as u16) >> 4)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user