Skip to content

Commit

Permalink
[ci] Prune access modifiers #723 (#728)
Browse files Browse the repository at this point in the history
* first batch

* second batch

* Update storage.rs

* batch 3

* add more types to public api

* revise pub(crate) in agdb

* Update graph.rs
  • Loading branch information
michaelvlach authored Sep 12, 2023
1 parent 9452d16 commit 04d8684
Show file tree
Hide file tree
Showing 71 changed files with 324 additions and 311 deletions.
22 changes: 11 additions & 11 deletions agdb/src/collections/indexed_map.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use super::map::DbMap;
use super::map::DbMapData;
use super::map::MapData;
use super::map::MapImpl;
use super::map::MapIterator;
use super::vec::VecValue;
use crate::db::db_error::DbError;
use crate::collections::map::DbMap;
use crate::collections::map::DbMapData;
use crate::collections::map::MapData;
use crate::collections::map::MapImpl;
use crate::collections::map::MapIterator;
use crate::collections::vec::VecValue;
use crate::storage::Storage;
use crate::storage::StorageData;
use crate::storage::StorageIndex;
use crate::utilities::stable_hash::StableHash;
use crate::DbError;
use crate::StorageData;
use std::marker::PhantomData;

pub struct IndexedMapImpl<K, T, D, DataKT, DataTK>
Expand All @@ -17,9 +17,9 @@ where
DataKT: MapData<K, T, D>,
DataTK: MapData<T, K, D>,
{
pub(crate) keys_to_values: MapImpl<K, T, D, DataKT>,
pub(crate) values_to_keys: MapImpl<T, K, D, DataTK>,
pub(crate) storage: PhantomData<D>,
keys_to_values: MapImpl<K, T, D, DataKT>,
values_to_keys: MapImpl<T, K, D, DataTK>,
storage: PhantomData<D>,
}

impl<K, T, D, DataKT, DataTK> IndexedMapImpl<K, T, D, DataKT, DataTK>
Expand Down
12 changes: 6 additions & 6 deletions agdb/src/collections/map.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use super::multi_map::MultiMapImpl;
use super::vec::DbVec;
use crate::collections::multi_map::MultiMapImpl;
use crate::collections::vec::DbVec;
use crate::collections::vec::VecValue;
use crate::db::db_error::DbError;
use crate::storage::Storage;
use crate::storage::StorageData;
use crate::storage::StorageIndex;
use crate::utilities::serialize::Serialize;
use crate::utilities::serialize::SerializeStatic;
use crate::utilities::stable_hash::StableHash;
use crate::DbError;
use crate::StorageData;
use std::marker::PhantomData;

#[derive(Clone, Debug, Default, Eq, PartialEq)]
Expand Down Expand Up @@ -338,8 +338,8 @@ where
D: StorageData,
Data: MapData<K, T, D>,
{
pub(crate) multi_map: MultiMapImpl<K, T, D, Data>,
pub(crate) storage: PhantomData<D>,
multi_map: MultiMapImpl<K, T, D, Data>,
storage: PhantomData<D>,
}

impl<K, T, D, Data> MapImpl<K, T, D, Data>
Expand Down
12 changes: 6 additions & 6 deletions agdb/src/collections/multi_map.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use super::map::DbMapData;
use super::map::MapData;
use super::map::MapIterator;
use super::map::MapValueState;
use crate::collections::map::DbMapData;
use crate::collections::map::MapData;
use crate::collections::map::MapIterator;
use crate::collections::map::MapValueState;
use crate::collections::vec::VecValue;
use crate::db::db_error::DbError;
use crate::storage::Storage;
use crate::storage::StorageData;
use crate::storage::StorageIndex;
use crate::utilities::stable_hash::StableHash;
use crate::DbError;
use crate::StorageData;
use std::marker::PhantomData;

pub struct MultiMapImpl<K, T, D, Data>
Expand Down
4 changes: 2 additions & 2 deletions agdb/src/collections/vec.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::db::db_error::DbError;
use crate::storage::Storage;
use crate::storage::StorageData;
use crate::storage::StorageIndex;
use crate::utilities::serialize::Serialize;
use crate::utilities::serialize::SerializeStatic;
use crate::DbError;
use crate::StorageData;
use std::marker::PhantomData;

pub trait VecData<T, D, E>
Expand Down
2 changes: 1 addition & 1 deletion agdb/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::graph::GraphIndex;
use crate::DbId;
use crate::DbKeyValue;

pub(crate) enum Command {
pub enum Command {
InsertAlias { alias: String, id: DbId },
InsertEdge { from: GraphIndex, to: GraphIndex },
InsertNode,
Expand Down
8 changes: 4 additions & 4 deletions agdb/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ use crate::storage::file_storage::FileStorage;
use crate::storage::file_storage_memory_mapped::FileStorageMemoryMapped;
use crate::storage::memory_storage::MemoryStorage;
use crate::storage::Storage;
use crate::storage::StorageData;
use crate::storage::StorageIndex;
use crate::transaction_mut::TransactionMut;
use crate::utilities::serialize::Serialize;
use crate::utilities::serialize::SerializeStatic;
use crate::DbId;
Expand All @@ -46,7 +44,9 @@ use crate::DbValue;
use crate::QueryError;
use crate::QueryResult;
use crate::SearchQueryAlgorithm;
use crate::StorageData;
use crate::Transaction;
use crate::TransactionMut;

#[derive(Default)]
struct DbStorageIndex {
Expand Down Expand Up @@ -724,13 +724,13 @@ impl<Store: StorageData> DbImpl<Store> {
.ok_or(DbError::from("Data integrity corrupted"))?;

for edge in node.edge_iter_from() {
edges.push((edge.index, edge.index_from(), edge.index_to()));
edges.push((edge.index(), edge.index_from(), edge.index_to()));
}

for edge in node.edge_iter_to() {
let from = edge.index_from();
if from != graph_index {
edges.push((edge.index, from, edge.index_to()));
edges.push((edge.index(), from, edge.index_to()));
}
}

Expand Down
2 changes: 1 addition & 1 deletion agdb/src/db/db_element.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::db_key_value::DbKeyValue;
use crate::DbId;
use crate::DbKeyValue;

/// Database element used in `QueryResult`
/// that represents a node or an edge.
Expand Down
2 changes: 1 addition & 1 deletion agdb/src/db/db_f64.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::db_error::DbError;
use crate::utilities::serialize::Serialize;
use crate::utilities::stable_hash::StableHash;
use crate::DbError;
use std::cmp::Ordering;
use std::hash::Hash;
use std::hash::Hasher;
Expand Down
4 changes: 2 additions & 2 deletions agdb/src/db/db_id.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::db_error::DbError;
use crate::collections::vec::VecValue;
use crate::storage::Storage;
use crate::storage::StorageData;
use crate::utilities::serialize::Serialize;
use crate::utilities::serialize::SerializeStatic;
use crate::utilities::stable_hash::StableHash;
use crate::DbError;
use crate::StorageData;

/// Database id is a wrapper around `i64`.
/// The id is an identifier of a database element
Expand Down
2 changes: 1 addition & 1 deletion agdb/src/db/db_key.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::db_value::DbValue;
use crate::DbValue;

/// Alias to `DbValue`
pub type DbKey = DbValue;
Expand Down
8 changes: 4 additions & 4 deletions agdb/src/db/db_key_value.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use super::db_error::DbError;
use super::db_value_index::DbValueIndex;
use crate::collections::vec::VecValue;
use crate::db::db_value_index::DbValueIndex;
use crate::storage::Storage;
use crate::storage::StorageData;
use crate::storage::StorageIndex;
use crate::utilities::serialize::Serialize;
use crate::utilities::serialize::SerializeStatic;
use crate::DbError;
use crate::DbKey;
use crate::DbValue;
use crate::StorageData;

/// Database key-value pair (aka property) attached to
/// database elements. It can be constructed from a
Expand Down Expand Up @@ -38,7 +38,7 @@ impl VecValue for DbKeyValue {
fn store<D: StorageData>(&self, storage: &mut Storage<D>) -> Result<Vec<u8>, DbError> {
let key_index = self.key.store_db_value(storage)?;
let value_index = self.value.store_db_value(storage)?;
Ok([key_index.value, value_index.value].concat())
Ok([key_index.data(), value_index.data()].concat())
}

fn load<D: StorageData>(storage: &Storage<D>, bytes: &[u8]) -> Result<Self, DbError> {
Expand Down
20 changes: 10 additions & 10 deletions agdb/src/db/db_search_handlers.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
use super::db_error::DbError;
use crate::graph::GraphIndex;
use crate::graph_search::PathSearchHandler;
use crate::graph_search::path_search::PathSearchHandler;
use crate::graph_search::SearchControl;
use crate::graph_search::SearchHandler;
use crate::query::query_condition::QueryCondition;
use crate::storage::StorageData;
use crate::DbError;
use crate::DbImpl;
use crate::QueryCondition;
use crate::StorageData;

pub(crate) struct DefaultHandler<'a, Store: StorageData> {
pub struct DefaultHandler<'a, Store: StorageData> {
db: &'a DbImpl<Store>,
conditions: &'a Vec<QueryCondition>,
}

pub(crate) struct LimitHandler<'a, Store: StorageData> {
pub struct LimitHandler<'a, Store: StorageData> {
limit: u64,
counter: u64,
db: &'a DbImpl<Store>,
conditions: &'a Vec<QueryCondition>,
}

pub(crate) struct OffsetHandler<'a, Store: StorageData> {
pub struct OffsetHandler<'a, Store: StorageData> {
offset: u64,
counter: u64,
db: &'a DbImpl<Store>,
conditions: &'a Vec<QueryCondition>,
}

pub(crate) struct LimitOffsetHandler<'a, Store: StorageData> {
pub struct LimitOffsetHandler<'a, Store: StorageData> {
limit: u64,
offset: u64,
counter: u64,
db: &'a DbImpl<Store>,
conditions: &'a Vec<QueryCondition>,
}

pub(crate) struct PathHandler<'a, Store: StorageData> {
pub struct PathHandler<'a, Store: StorageData> {
db: &'a DbImpl<Store>,
conditions: &'a Vec<QueryCondition>,
}

impl<'a, Store: StorageData> DefaultHandler<'a, Store> {
pub(crate) fn new(db: &'a DbImpl<Store>, conditions: &'a Vec<QueryCondition>) -> Self {
pub fn new(db: &'a DbImpl<Store>, conditions: &'a Vec<QueryCondition>) -> Self {
Self { db, conditions }
}
}
Expand Down
28 changes: 14 additions & 14 deletions agdb/src/db/db_value.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::db_error::DbError;
use super::db_f64::DbF64;
use super::db_value_index::DbValueIndex;
use crate::db::db_f64::DbF64;
use crate::db::db_value_index::DbValueIndex;
use crate::storage::Storage;
use crate::storage::StorageData;
use crate::storage::StorageIndex;
use crate::utilities::stable_hash::StableHash;
use crate::DbError;
use crate::StorageData;
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result as DisplayResult;
Expand Down Expand Up @@ -49,15 +49,15 @@ pub enum DbValue {
VecString(Vec<String>),
}

pub(crate) const BYTES_META_VALUE: u8 = 1_u8;
pub(crate) const I64_META_VALUE: u8 = 2_u8;
pub(crate) const U64_META_VALUE: u8 = 3_u8;
pub(crate) const F64_META_VALUE: u8 = 4_u8;
pub(crate) const STRING_META_VALUE: u8 = 5_u8;
pub(crate) const VEC_I64_META_VALUE: u8 = 6_u8;
pub(crate) const VEC_U64_META_VALUE: u8 = 7_u8;
pub(crate) const VEC_F64_META_VALUE: u8 = 8_u8;
pub(crate) const VEC_STRING_META_VALUE: u8 = 9_u8;
const BYTES_META_VALUE: u8 = 1_u8;
const I64_META_VALUE: u8 = 2_u8;
const U64_META_VALUE: u8 = 3_u8;
const F64_META_VALUE: u8 = 4_u8;
const STRING_META_VALUE: u8 = 5_u8;
const VEC_I64_META_VALUE: u8 = 6_u8;
const VEC_U64_META_VALUE: u8 = 7_u8;
const VEC_F64_META_VALUE: u8 = 8_u8;
const VEC_STRING_META_VALUE: u8 = 9_u8;

impl DbValue {
/// Returns `&Vec<u8>` or an error if the value is
Expand Down Expand Up @@ -779,7 +779,7 @@ mod tests {
#[should_panic]
fn bad_deserialization() {
let test_file = TestFile::new();
let storage = Storage::<FileStorage>::new(&test_file.filename).unwrap();
let storage = Storage::<FileStorage>::new(test_file.file_name()).unwrap();

let _ = DbValue::load_db_value(DbValueIndex::new(), &storage);
}
Expand Down
28 changes: 16 additions & 12 deletions agdb/src/db/db_value_index.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
use super::db_error::DbError;
use crate::utilities::serialize::Serialize;
use crate::utilities::serialize::SerializeStatic;
use crate::DbError;

#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub(crate) struct DbValueIndex {
pub(crate) value: [u8; 16],
pub struct DbValueIndex {
value: [u8; 16],
}

impl DbValueIndex {
pub(crate) fn new() -> Self {
pub fn new() -> Self {
Self { value: [0_u8; 16] }
}

pub(crate) fn get_type(&self) -> u8 {
pub fn data(&self) -> [u8; 16] {
self.value
}

pub fn get_type(&self) -> u8 {
self.value[15] >> 4
}

pub(crate) fn index(&self) -> u64 {
pub fn index(&self) -> u64 {
let mut bytes = [0_u8; 8];
bytes.copy_from_slice(&self.value[0..std::mem::size_of::<u64>()]);
u64::from_le_bytes(bytes)
}

pub(crate) fn is_value(&self) -> bool {
pub fn is_value(&self) -> bool {
self.size() != 0 || self.index() == 0
}

pub(crate) fn set_type(&mut self, value: u8) {
pub fn set_type(&mut self, value: u8) {
let v = (value << 4) | self.size();
self.value[15] = v;
}

pub(crate) fn set_index(&mut self, index: u64) {
pub fn set_index(&mut self, index: u64) {
self.set_size(0);
self.value[0..std::mem::size_of::<u64>()].copy_from_slice(&index.to_le_bytes());
}

pub(crate) fn set_value(&mut self, value: &[u8]) -> bool {
pub fn set_value(&mut self, value: &[u8]) -> bool {
if value.len() > 15 {
return false;
}
Expand All @@ -47,11 +51,11 @@ impl DbValueIndex {
true
}

pub(crate) fn size(&self) -> u8 {
pub fn size(&self) -> u8 {
self.value[15] & 0b00001111
}

pub(crate) fn value(&self) -> &[u8] {
pub fn value(&self) -> &[u8] {
let pos = self.size();
&self.value[0..(pos as usize)]
}
Expand Down
Loading

0 comments on commit 04d8684

Please sign in to comment.