~ntietz/isabella-db

0b8fdc04be43115076b71d39d600a6fdf6c09f11 — Conner Bondurant 1 year, 3 months ago 70ec5b3
Add custom debug impl for large types
M bitmap/src/dense.rs => bitmap/src/dense.rs +11 -1
@@ 1,3 1,4 @@
use std::fmt::Debug;
use std::ops::{BitAnd, BitOr, Not};

use super::util::div_with_rem;


@@ 5,12 6,21 @@ use super::{BitmapError, ItemID};

/// DenseBitmap stores one bit for each record that's indexed. It has a fixed
/// size assigned at creation and cannot be resized.
#[derive(Debug, PartialEq, Eq)]
#[derive(PartialEq, Eq)]
pub struct DenseBitmap {
    chunks: Vec<usize>,
    size: usize,
}

impl Debug for DenseBitmap {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("DenseBitmap")
            .field("chunks.len()", &self.chunks.len())
            .field("size", &self.size)
            .finish()
    }
}

pub struct DenseBitmapIterator<'a> {
    bitmap: &'a DenseBitmap,
    item_id: usize,

M bitmap/src/sparse.rs => bitmap/src/sparse.rs +13 -1
@@ 1,3 1,5 @@
use std::fmt::Debug;

use serde::{Deserialize, Serialize};

use super::{BitmapError, ItemID};


@@ 10,13 12,23 @@ pub struct Run {
/// SparseBitmap stores contiguous runs of the same value, rather than each bit
/// individually. It has a fixed size assigned at creation and cannot be
/// resized.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize)]
pub struct SparseBitmap {
    runs: Vec<Run>,
    size: usize,
    run_length: usize,
}

impl Debug for SparseBitmap {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("SparseBitmap")
            .field("runs.len()", &self.runs.len())
            .field("size", &self.size)
            .field("run_length", &self.run_length)
            .finish()
    }
}

impl SparseBitmap {
    pub fn of_size(size: usize) -> Self {
        // initially, we only have one run, so everything is 0s.

M isabella/src/db/mod.rs => isabella/src/db/mod.rs +11 -0
@@ 1,3 1,5 @@
use std::fmt::Debug;

use pgn::PgnFile;
use serde::{Deserialize, Serialize};
use shakmaty::Chess;


@@ 13,6 15,15 @@ pub struct GameDB {
    strings: StringsTable,
}

impl Debug for GameDB {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("GameDB")
            .field("games.len()", &self.games.len())
            .field("strings", &self.strings)
            .finish()
    }
}

impl GameDB {
    pub fn new() -> Self {
        GameDB {

M isabella/src/game/mod.rs => isabella/src/game/mod.rs +1 -1
@@ 14,7 14,7 @@ pub enum StartingPosition {
    Custom(#[serde(with = "chess_serde")] Chess),
}

#[derive(Default, Serialize, Deserialize)]
#[derive(Default, Debug, Serialize, Deserialize)]
pub struct Game {
    pub starting_position: StartingPosition,
    #[serde(default, with = "vec_move_def")]

M isabella/src/index/unique_fixed.rs => isabella/src/index/unique_fixed.rs +11 -0
@@ 1,3 1,5 @@
use std::fmt::Debug;

use serde::{Deserialize, Serialize};

/// UniqueFixedIndex is a fixed-size container allowing locating a given value


@@ 15,6 17,15 @@ pub struct UniqueFixedIndex<K, V> {
    vals: Vec<V>,
}

impl<K, V> Debug for UniqueFixedIndex<K, V> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("UniqueFixedIndex")
            .field("keys.len()", &self.keys.len())
            .field("vals.len()", &self.vals.len())
            .finish()
    }
}

impl<K, V> UniqueFixedIndex<K, V>
where
    K: Ord,

M isabella/src/strings.rs => isabella/src/strings.rs +10 -0
@@ 1,5 1,6 @@
use std::collections::hash_map::DefaultHasher;
use std::collections::HashMap;
use std::fmt::Debug;
use std::hash::{Hash, Hasher};

use serde::{Deserialize, Serialize};


@@ 16,6 17,15 @@ pub struct StringsTable {
    ids: HashMap<StringHash, StringID>,
}

impl Debug for StringsTable {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("StringsTable")
            .field("strings.len()", &self.strings.len())
            .field("ids.len()", &self.ids.len())
            .finish()
    }
}

impl StringsTable {
    /// create a new StringsTable with no default capacity
    pub fn new() -> Self {