mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-30 12:01:57 +00:00
use btreeset instead of indexset
This commit is contained in:
committed by
Aiden McClelland
parent
dee4ce15bd
commit
0db5657b7f
@@ -16,7 +16,6 @@ version = "0.1.0"
|
|||||||
async-trait = "0.1.42"
|
async-trait = "0.1.42"
|
||||||
fd-lock-rs = "0.1.3"
|
fd-lock-rs = "0.1.3"
|
||||||
futures = "0.3.8"
|
futures = "0.3.8"
|
||||||
indexmap = { version = "1.6.2", features = ["serde"] }
|
|
||||||
json-patch = { path = "../json-patch" }
|
json-patch = { path = "../json-patch" }
|
||||||
json-ptr = { path = "../json-ptr" }
|
json-ptr = { path = "../json-ptr" }
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use indexmap::IndexSet;
|
|
||||||
use json_ptr::{JsonPointer, SegList};
|
use json_ptr::{JsonPointer, SegList};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
use std::collections::BTreeSet;
|
||||||
use tokio::sync::{broadcast::Receiver, RwLock, RwLockReadGuard};
|
use tokio::sync::{broadcast::Receiver, RwLock, RwLockReadGuard};
|
||||||
|
|
||||||
use crate::{locker::Guard, Locker, PatchDb, Revision, Store, Transaction};
|
use crate::{locker::Guard, Locker, PatchDb, Revision, Store, Transaction};
|
||||||
@@ -27,7 +27,7 @@ pub trait DbHandle: Send + Sync {
|
|||||||
&mut self,
|
&mut self,
|
||||||
ptr: &JsonPointer<S, V>,
|
ptr: &JsonPointer<S, V>,
|
||||||
store_read_lock: Option<RwLockReadGuard<'_, Store>>,
|
store_read_lock: Option<RwLockReadGuard<'_, Store>>,
|
||||||
) -> Result<IndexSet<String>, Error>;
|
) -> Result<BTreeSet<String>, Error>;
|
||||||
async fn get_value<S: AsRef<str> + Send + Sync, V: SegList + Send + Sync>(
|
async fn get_value<S: AsRef<str> + Send + Sync, V: SegList + Send + Sync>(
|
||||||
&mut self,
|
&mut self,
|
||||||
ptr: &JsonPointer<S, V>,
|
ptr: &JsonPointer<S, V>,
|
||||||
@@ -101,7 +101,7 @@ impl<Handle: DbHandle + ?Sized> DbHandle for &mut Handle {
|
|||||||
&mut self,
|
&mut self,
|
||||||
ptr: &JsonPointer<S, V>,
|
ptr: &JsonPointer<S, V>,
|
||||||
store_read_lock: Option<RwLockReadGuard<'_, Store>>,
|
store_read_lock: Option<RwLockReadGuard<'_, Store>>,
|
||||||
) -> Result<IndexSet<String>, Error> {
|
) -> Result<BTreeSet<String>, Error> {
|
||||||
(*self).keys(ptr, store_read_lock).await
|
(*self).keys(ptr, store_read_lock).await
|
||||||
}
|
}
|
||||||
async fn get_value<S: AsRef<str> + Send + Sync, V: SegList + Send + Sync>(
|
async fn get_value<S: AsRef<str> + Send + Sync, V: SegList + Send + Sync>(
|
||||||
@@ -201,7 +201,7 @@ impl DbHandle for PatchDbHandle {
|
|||||||
&mut self,
|
&mut self,
|
||||||
ptr: &JsonPointer<S, V>,
|
ptr: &JsonPointer<S, V>,
|
||||||
store_read_lock: Option<RwLockReadGuard<'_, Store>>,
|
store_read_lock: Option<RwLockReadGuard<'_, Store>>,
|
||||||
) -> Result<IndexSet<String>, Error> {
|
) -> Result<BTreeSet<String>, Error> {
|
||||||
if let Some(lock) = store_read_lock {
|
if let Some(lock) = store_read_lock {
|
||||||
lock.keys(ptr)
|
lock.keys(ptr)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, BTreeSet, HashMap};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use indexmap::{IndexMap, IndexSet};
|
|
||||||
use json_patch::{Patch, PatchOperation, RemoveOperation};
|
use json_patch::{Patch, PatchOperation, RemoveOperation};
|
||||||
use json_ptr::JsonPointer;
|
use json_ptr::JsonPointer;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -444,13 +443,6 @@ impl<K: AsRef<str> + Ord, V> Map for BTreeMap<K, V> {
|
|||||||
self.get(key)
|
self.get(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<K: AsRef<str> + Eq + Hash, V> Map for IndexMap<K, V> {
|
|
||||||
type Key = K;
|
|
||||||
type Value = V;
|
|
||||||
fn get(&self, key: &Self::Key) -> Option<&Self::Value> {
|
|
||||||
IndexMap::get(self, key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MapModel<T>(Model<T>)
|
pub struct MapModel<T>(Model<T>)
|
||||||
@@ -497,14 +489,14 @@ where
|
|||||||
impl<T> MapModel<T>
|
impl<T> MapModel<T>
|
||||||
where
|
where
|
||||||
T: Serialize + for<'de> Deserialize<'de> + Map,
|
T: Serialize + for<'de> Deserialize<'de> + Map,
|
||||||
T::Key: Hash + Eq + for<'de> Deserialize<'de>,
|
T::Key: Ord + Eq + for<'de> Deserialize<'de>,
|
||||||
T::Value: Serialize + for<'de> Deserialize<'de>,
|
T::Value: Serialize + for<'de> Deserialize<'de>,
|
||||||
{
|
{
|
||||||
pub async fn keys<Db: DbHandle>(
|
pub async fn keys<Db: DbHandle>(
|
||||||
&self,
|
&self,
|
||||||
db: &mut Db,
|
db: &mut Db,
|
||||||
lock: bool,
|
lock: bool,
|
||||||
) -> Result<IndexSet<T::Key>, Error> {
|
) -> Result<BTreeSet<T::Key>, Error> {
|
||||||
if lock {
|
if lock {
|
||||||
db.lock(self.as_ref().clone(), false).await;
|
db.lock(self.as_ref().clone(), false).await;
|
||||||
}
|
}
|
||||||
@@ -584,10 +576,3 @@ where
|
|||||||
{
|
{
|
||||||
type Model = MapModel<BTreeMap<K, V>>;
|
type Model = MapModel<BTreeMap<K, V>>;
|
||||||
}
|
}
|
||||||
impl<K, V> HasModel for IndexMap<K, V>
|
|
||||||
where
|
|
||||||
K: Serialize + for<'de> Deserialize<'de> + Hash + Eq + AsRef<str>,
|
|
||||||
V: Serialize + for<'de> Deserialize<'de>,
|
|
||||||
{
|
|
||||||
type Model = MapModel<IndexMap<K, V>>;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use indexmap::IndexSet;
|
|
||||||
use json_patch::{AddOperation, Patch, PatchOperation, RemoveOperation, ReplaceOperation};
|
use json_patch::{AddOperation, Patch, PatchOperation, RemoveOperation, ReplaceOperation};
|
||||||
use json_ptr::{JsonPointer, SegList};
|
use json_ptr::{JsonPointer, SegList};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
@@ -185,7 +185,7 @@ impl DiffPatch {
|
|||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn keys(&self, mut keys: IndexSet<String>) -> IndexSet<String> {
|
pub fn keys(&self, mut keys: BTreeSet<String>) -> BTreeSet<String> {
|
||||||
for op in &(self.0).0 {
|
for op in &(self.0).0 {
|
||||||
match op {
|
match op {
|
||||||
PatchOperation::Add(a) => {
|
PatchOperation::Add(a) => {
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ use std::sync::atomic::AtomicU64;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use fd_lock_rs::FdLock;
|
use fd_lock_rs::FdLock;
|
||||||
use indexmap::IndexSet;
|
|
||||||
use json_ptr::{JsonPointer, SegList};
|
use json_ptr::{JsonPointer, SegList};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
use std::collections::BTreeSet;
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
use tokio::sync::broadcast::{Receiver, Sender};
|
use tokio::sync::broadcast::{Receiver, Sender};
|
||||||
use tokio::sync::{Mutex, OwnedMutexGuard, RwLock, RwLockWriteGuard};
|
use tokio::sync::{Mutex, OwnedMutexGuard, RwLock, RwLockWriteGuard};
|
||||||
@@ -132,10 +132,10 @@ impl Store {
|
|||||||
pub(crate) fn keys<S: AsRef<str>, V: SegList>(
|
pub(crate) fn keys<S: AsRef<str>, V: SegList>(
|
||||||
&self,
|
&self,
|
||||||
ptr: &JsonPointer<S, V>,
|
ptr: &JsonPointer<S, V>,
|
||||||
) -> Result<IndexSet<String>, Error> {
|
) -> Result<BTreeSet<String>, Error> {
|
||||||
Ok(match ptr.get(self.get_data()?).unwrap_or(&Value::Null) {
|
Ok(match ptr.get(self.get_data()?).unwrap_or(&Value::Null) {
|
||||||
Value::Object(o) => o.keys().cloned().collect(),
|
Value::Object(o) => o.keys().cloned().collect(),
|
||||||
_ => IndexSet::new(),
|
_ => BTreeSet::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub(crate) fn get<T: for<'de> Deserialize<'de>, S: AsRef<str>, V: SegList>(
|
pub(crate) fn get<T: for<'de> Deserialize<'de>, S: AsRef<str>, V: SegList>(
|
||||||
@@ -240,7 +240,7 @@ impl PatchDb {
|
|||||||
pub async fn keys<S: AsRef<str>, V: SegList>(
|
pub async fn keys<S: AsRef<str>, V: SegList>(
|
||||||
&self,
|
&self,
|
||||||
ptr: &JsonPointer<S, V>,
|
ptr: &JsonPointer<S, V>,
|
||||||
) -> Result<IndexSet<String>, Error> {
|
) -> Result<BTreeSet<String>, Error> {
|
||||||
self.store.read().await.keys(ptr)
|
self.store.read().await.keys(ptr)
|
||||||
}
|
}
|
||||||
pub async fn get<T: for<'de> Deserialize<'de>, S: AsRef<str>, V: SegList>(
|
pub async fn get<T: for<'de> Deserialize<'de>, S: AsRef<str>, V: SegList>(
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use indexmap::IndexSet;
|
|
||||||
use json_ptr::{JsonPointer, SegList};
|
use json_ptr::{JsonPointer, SegList};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
use std::collections::BTreeSet;
|
||||||
use tokio::sync::broadcast::error::TryRecvError;
|
use tokio::sync::broadcast::error::TryRecvError;
|
||||||
use tokio::sync::broadcast::Receiver;
|
use tokio::sync::broadcast::Receiver;
|
||||||
use tokio::sync::{RwLock, RwLockReadGuard};
|
use tokio::sync::{RwLock, RwLockReadGuard};
|
||||||
@@ -123,7 +123,7 @@ impl<Parent: DbHandle + Send + Sync> DbHandle for Transaction<Parent> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
ptr: &JsonPointer<S, V>,
|
ptr: &JsonPointer<S, V>,
|
||||||
store_read_lock: Option<RwLockReadGuard<'_, Store>>,
|
store_read_lock: Option<RwLockReadGuard<'_, Store>>,
|
||||||
) -> Result<IndexSet<String>, Error> {
|
) -> Result<BTreeSet<String>, Error> {
|
||||||
let keys = {
|
let keys = {
|
||||||
let store_lock = self.parent.store();
|
let store_lock = self.parent.store();
|
||||||
let store = if let Some(store_read_lock) = store_read_lock {
|
let store = if let Some(store_read_lock) = store_read_lock {
|
||||||
|
|||||||
Reference in New Issue
Block a user