mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-26 15:49:58 -07:00
parser: split txid_to_txdata db
This commit is contained in:
@@ -38,7 +38,7 @@ where
|
||||
}
|
||||
|
||||
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>
|
||||
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 {
|
||||
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(|| {
|
||||
let db_name = format!(
|
||||
"{}..{}",
|
||||
db_index * DB_MAX_SIZE,
|
||||
(db_index + 1) * DB_MAX_SIZE
|
||||
db_index * ADDRESS_INDEX_DB_MAX_SIZE,
|
||||
(db_index + 1) * ADDRESS_INDEX_DB_MAX_SIZE
|
||||
);
|
||||
|
||||
Database::open(Self::folder(), &db_name).unwrap()
|
||||
@@ -120,7 +120,7 @@ impl AddressIndexToAddressData {
|
||||
}
|
||||
|
||||
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 super::{AnyDatabaseGroup, Database as _Database, Metadata};
|
||||
use super::{AnyDatabaseGroup, Database as _Database, Metadata, ADDRESS_INDEX_DB_MAX_SIZE};
|
||||
|
||||
type Key = u32;
|
||||
type Value = EmptyAddressData;
|
||||
@@ -36,8 +36,6 @@ impl DerefMut for AddressIndexToEmptyAddressData {
|
||||
}
|
||||
}
|
||||
|
||||
const DB_MAX_SIZE: usize = 500_000;
|
||||
|
||||
impl AddressIndexToEmptyAddressData {
|
||||
pub fn unsafe_insert(&mut self, key: Key, value: Value) -> Option<Value> {
|
||||
self.metadata.called_insert();
|
||||
@@ -76,8 +74,8 @@ impl AddressIndexToEmptyAddressData {
|
||||
self.entry(db_index).or_insert_with(|| {
|
||||
let db_name = format!(
|
||||
"{}..{}",
|
||||
db_index * DB_MAX_SIZE,
|
||||
(db_index + 1) * DB_MAX_SIZE
|
||||
db_index * ADDRESS_INDEX_DB_MAX_SIZE,
|
||||
(db_index + 1) * ADDRESS_INDEX_DB_MAX_SIZE
|
||||
);
|
||||
|
||||
Database::open(Self::folder(), &db_name).unwrap()
|
||||
@@ -85,7 +83,7 @@ impl AddressIndexToEmptyAddressData {
|
||||
}
|
||||
|
||||
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 metadata: Metadata,
|
||||
|
||||
map: BTreeMap<u8, Database>,
|
||||
map: BTreeMap<u16, Database>,
|
||||
}
|
||||
|
||||
impl Deref for TxidToTxData {
|
||||
type Target = BTreeMap<u8, Database>;
|
||||
type Target = BTreeMap<u16, Database>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.map
|
||||
@@ -113,8 +113,8 @@ impl TxidToTxData {
|
||||
U8x31::from(&txid[1..])
|
||||
}
|
||||
|
||||
fn db_index(txid: &Txid) -> u8 {
|
||||
txid[0]
|
||||
fn db_index(txid: &Txid) -> u16 {
|
||||
((txid[0] as u16) << 4) + ((txid[1] as u16) >> 4)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user