switch to indexmap

This commit is contained in:
Aiden McClelland
2021-05-24 17:13:51 -06:00
parent dde77084a4
commit f5fecf0aba
6 changed files with 15 additions and 15 deletions

View File

@@ -16,7 +16,7 @@ version = "0.1.0"
async-trait = "0.1.42"
fd-lock-rs = "0.1.3"
futures = "0.3.8"
hashlink = "0.6.0"
indexmap = "1.6.2"
json-patch = { path = "../json-patch" }
json-ptr = { path = "../json-ptr" }
lazy_static = "1.4.0"

View File

@@ -1,7 +1,7 @@
use std::sync::Arc;
use async_trait::async_trait;
use hashlink::LinkedHashSet;
use indexmap::IndexSet;
use json_ptr::{JsonPointer, SegList};
use serde::{Deserialize, Serialize};
use serde_json::Value;
@@ -29,7 +29,7 @@ pub trait DbHandle: Sized + Send + Sync {
&mut self,
ptr: &JsonPointer<S, V>,
store_read_lock: Option<RwLockReadGuard<'_, Store>>,
) -> Result<LinkedHashSet<String>, Error>;
) -> Result<IndexSet<String>, Error>;
async fn get_value<S: AsRef<str> + Send + Sync, V: SegList + Send + Sync>(
&mut self,
ptr: &JsonPointer<S, V>,
@@ -103,7 +103,7 @@ impl<Handle: DbHandle + Send + Sync> DbHandle for &mut Handle {
&mut self,
ptr: &JsonPointer<S, V>,
store_read_lock: Option<RwLockReadGuard<'_, Store>>,
) -> Result<LinkedHashSet<String>, Error> {
) -> Result<IndexSet<String>, Error> {
(*self).keys(ptr, store_read_lock).await
}
async fn get_value<S: AsRef<str> + Send + Sync, V: SegList + Send + Sync>(
@@ -195,7 +195,7 @@ impl DbHandle for PatchDbHandle {
&mut self,
ptr: &JsonPointer<S, V>,
store_read_lock: Option<RwLockReadGuard<'_, Store>>,
) -> Result<LinkedHashSet<String>, Error> {
) -> Result<IndexSet<String>, Error> {
if let Some(lock) = store_read_lock {
lock.keys(ptr)
} else {

View File

@@ -3,7 +3,7 @@ use std::hash::Hash;
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
use hashlink::LinkedHashSet;
use indexmap::IndexSet;
use json_ptr::JsonPointer;
use serde::{Deserialize, Serialize};
use serde_json::Value;
@@ -425,7 +425,7 @@ where
T::Key: Hash + Eq + for<'de> Deserialize<'de>,
T::Value: Serialize + for<'de> Deserialize<'de>,
{
pub async fn keys<Db: DbHandle>(&self, db: &mut Db) -> Result<LinkedHashSet<T::Key>, Error> {
pub async fn keys<Db: DbHandle>(&self, db: &mut Db) -> Result<IndexSet<T::Key>, Error> {
db.lock(self.as_ref(), LockType::Read).await;
let set = db.keys(self.as_ref(), None).await?;
Ok(set

View File

@@ -1,6 +1,6 @@
use std::ops::Deref;
use hashlink::LinkedHashSet;
use indexmap::IndexSet;
use json_patch::{AddOperation, Patch, PatchOperation, RemoveOperation, ReplaceOperation};
use json_ptr::{JsonPointer, SegList};
use serde::{Deserialize, Serialize};
@@ -178,7 +178,7 @@ impl DiffPatch {
res
}
pub fn keys(&self, mut keys: LinkedHashSet<String>) -> LinkedHashSet<String> {
pub fn keys(&self, mut keys: IndexSet<String>) -> IndexSet<String> {
for op in &(self.0).0 {
match op {
PatchOperation::Add(a) => {

View File

@@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
use std::sync::Arc;
use fd_lock_rs::FdLock;
use hashlink::LinkedHashSet;
use indexmap::IndexSet;
use json_ptr::{JsonPointer, SegList};
use lazy_static::lazy_static;
use qutex_2::{Guard, Qutex};
@@ -132,10 +132,10 @@ impl Store {
pub(crate) fn keys<S: AsRef<str>, V: SegList>(
&self,
ptr: &JsonPointer<S, V>,
) -> Result<LinkedHashSet<String>, Error> {
) -> Result<IndexSet<String>, Error> {
Ok(match ptr.get(self.get_data()?).unwrap_or(&Value::Null) {
Value::Object(o) => o.keys().cloned().collect(),
_ => LinkedHashSet::new(),
_ => IndexSet::new(),
})
}
pub(crate) fn get<T: for<'de> Deserialize<'de>, S: AsRef<str>, V: SegList>(
@@ -226,7 +226,7 @@ impl PatchDb {
pub async fn keys<S: AsRef<str>, V: SegList>(
&self,
ptr: &JsonPointer<S, V>,
) -> Result<LinkedHashSet<String>, Error> {
) -> Result<IndexSet<String>, Error> {
self.store.read().await.keys(ptr)
}
pub async fn get<T: for<'de> Deserialize<'de>, S: AsRef<str>, V: SegList>(

View File

@@ -1,7 +1,7 @@
use std::sync::Arc;
use async_trait::async_trait;
use hashlink::LinkedHashSet;
use indexmap::IndexSet;
use json_ptr::{JsonPointer, SegList};
use serde::{Deserialize, Serialize};
use serde_json::Value;
@@ -110,7 +110,7 @@ impl<Parent: DbHandle + Send + Sync> DbHandle for Transaction<Parent> {
&mut self,
ptr: &JsonPointer<S, V>,
store_read_lock: Option<RwLockReadGuard<'_, Store>>,
) -> Result<LinkedHashSet<String>, Error> {
) -> Result<IndexSet<String>, Error> {
let keys = {
let store_lock = self.parent.store();
let store = if let Some(store_read_lock) = store_read_lock {