1
0
mirror of https://github.com/tensorchord/pgvecto.rs.git synced 2025-08-01 06:46:52 +03:00

refactor: refine delete RPC (#351)

Signed-off-by: usamoi <usamoi@outlook.com>
This commit is contained in:
Usamoi
2024-02-07 10:31:40 +08:00
committed by GitHub
parent 6d4745b3ed
commit a4f5d28c10
14 changed files with 290 additions and 156 deletions

View File

@ -448,6 +448,25 @@ impl<S: G> IndexView<S> {
}
}))
}
pub fn list(&self) -> impl Iterator<Item = Pointer> + '_ {
let sealed = self
.sealed
.values()
.flat_map(|x| (0..x.len()).map(|i| x.payload(i)));
let growing = self
.growing
.values()
.flat_map(|x| (0..x.len()).map(|i| x.payload(i)));
let write = self
.write
.iter()
.map(|(_, x)| x)
.flat_map(|x| (0..x.len()).map(|i| x.payload(i)));
sealed
.chain(growing)
.chain(write)
.filter_map(|p| self.delete.check(p))
}
pub fn insert(
&self,
vector: Vec<S::Scalar>,
@ -467,37 +486,8 @@ impl<S: G> IndexView<S> {
Ok(Err(OutdatedError))
}
}
pub fn delete<F: FnMut(Pointer) -> bool>(&self, mut f: F) {
for (_, sealed) in self.sealed.iter() {
let n = sealed.len();
for i in 0..n {
if let Some(p) = self.delete.check(sealed.payload(i)) {
if f(p) {
self.delete.delete(p);
}
}
}
}
for (_, growing) in self.growing.iter() {
let n = growing.len();
for i in 0..n {
if let Some(p) = self.delete.check(growing.payload(i)) {
if f(p) {
self.delete.delete(p);
}
}
}
}
if let Some((_, write)) = &self.write {
let n = write.len();
for i in 0..n {
if let Some(p) = self.delete.check(write.payload(i)) {
if f(p) {
self.delete.delete(p);
}
}
}
}
pub fn delete(&self, p: Pointer) {
self.delete.delete(p);
}
pub fn flush(&self) {
self.delete.flush();

View File

@ -173,6 +173,16 @@ impl InstanceView {
_ => Err(ServiceError::Unmatched),
}
}
pub fn list(&self) -> impl Iterator<Item = Pointer> + '_ {
match self {
InstanceView::F32Cos(x) => Box::new(x.list()) as Box<dyn Iterator<Item = Pointer>>,
InstanceView::F32Dot(x) => Box::new(x.list()),
InstanceView::F32L2(x) => Box::new(x.list()),
InstanceView::F16Cos(x) => Box::new(x.list()),
InstanceView::F16Dot(x) => Box::new(x.list()),
InstanceView::F16L2(x) => Box::new(x.list()),
}
}
pub fn insert(
&self,
vector: DynamicVector,
@ -188,14 +198,14 @@ impl InstanceView {
_ => Err(ServiceError::Unmatched),
}
}
pub fn delete<F: FnMut(Pointer) -> bool>(&self, f: F) {
pub fn delete(&self, pointer: Pointer) {
match self {
InstanceView::F32Cos(x) => x.delete(f),
InstanceView::F32Dot(x) => x.delete(f),
InstanceView::F32L2(x) => x.delete(f),
InstanceView::F16Cos(x) => x.delete(f),
InstanceView::F16Dot(x) => x.delete(f),
InstanceView::F16L2(x) => x.delete(f),
InstanceView::F32Cos(x) => x.delete(pointer),
InstanceView::F32Dot(x) => x.delete(pointer),
InstanceView::F32L2(x) => x.delete(pointer),
InstanceView::F16Cos(x) => x.delete(pointer),
InstanceView::F16Dot(x) => x.delete(pointer),
InstanceView::F16L2(x) => x.delete(pointer),
}
}
pub fn flush(&self) {