-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move pgvecto.rs base to this repo
Signed-off-by: usamoi <[email protected]>
- Loading branch information
Showing
87 changed files
with
7,981 additions
and
963 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() { | ||
println!(r#"cargo::rustc-check-cfg=cfg(pgrx_embed)"#); | ||
println!(r#"cargo::rustc-check-cfg=cfg(feature, values("pg12"))"#); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "algorithm" | ||
version.workspace = true | ||
edition.workspace = true | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::ops::{Deref, DerefMut}; | ||
|
||
#[repr(C, align(8))] | ||
pub struct Opaque { | ||
pub next: u32, | ||
pub skip: u32, | ||
} | ||
|
||
pub trait Page: Sized { | ||
fn get_opaque(&self) -> &Opaque; | ||
fn get_opaque_mut(&mut self) -> &mut Opaque; | ||
fn len(&self) -> u16; | ||
fn get(&self, i: u16) -> Option<&[u8]>; | ||
fn get_mut(&mut self, i: u16) -> Option<&mut [u8]>; | ||
fn alloc(&mut self, data: &[u8]) -> Option<u16>; | ||
fn free(&mut self, i: u16); | ||
fn reconstruct(&mut self, removes: &[u16]); | ||
fn freespace(&self) -> u16; | ||
} | ||
|
||
pub trait PageGuard { | ||
fn id(&self) -> u32; | ||
} | ||
|
||
pub trait RelationRead { | ||
type Page: Page; | ||
type ReadGuard<'a>: PageGuard + Deref<Target = Self::Page> | ||
where | ||
Self: 'a; | ||
fn read(&self, id: u32) -> Self::ReadGuard<'_>; | ||
} | ||
|
||
pub trait RelationWrite: RelationRead { | ||
type WriteGuard<'a>: PageGuard + DerefMut<Target = Self::Page> | ||
where | ||
Self: 'a; | ||
fn write(&self, id: u32, tracking_freespace: bool) -> Self::WriteGuard<'_>; | ||
fn extend(&self, tracking_freespace: bool) -> Self::WriteGuard<'_>; | ||
fn search(&self, freespace: usize) -> Option<Self::WriteGuard<'_>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "always_equal" | ||
version.workspace = true | ||
edition.workspace = true | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use std::cmp::Ordering; | ||
use std::hash::Hash; | ||
|
||
#[derive(Debug, Clone, Copy, Default)] | ||
#[repr(transparent)] | ||
pub struct AlwaysEqual<T>(pub T); | ||
|
||
impl<T> PartialEq for AlwaysEqual<T> { | ||
fn eq(&self, _: &Self) -> bool { | ||
true | ||
} | ||
} | ||
|
||
impl<T> Eq for AlwaysEqual<T> {} | ||
|
||
impl<T> PartialOrd for AlwaysEqual<T> { | ||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
Some(self.cmp(other)) | ||
} | ||
} | ||
|
||
impl<T> Ord for AlwaysEqual<T> { | ||
fn cmp(&self, _: &Self) -> Ordering { | ||
Ordering::Equal | ||
} | ||
} | ||
|
||
impl<T> Hash for AlwaysEqual<T> { | ||
fn hash<H: std::hash::Hasher>(&self, _: &mut H) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "distance" | ||
version.workspace = true | ||
edition.workspace = true | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
#[repr(transparent)] | ||
pub struct Distance(i32); | ||
|
||
impl Distance { | ||
pub const ZERO: Self = Distance::from_f32(0.0f32); | ||
pub const INFINITY: Self = Distance::from_f32(f32::INFINITY); | ||
pub const NEG_INFINITY: Self = Distance::from_f32(f32::NEG_INFINITY); | ||
|
||
#[inline(always)] | ||
pub const fn from_f32(value: f32) -> Self { | ||
let bits = value.to_bits() as i32; | ||
let mask = ((bits >> 31) as u32) >> 1; | ||
let res = bits ^ (mask as i32); | ||
Self(res) | ||
} | ||
|
||
#[inline(always)] | ||
pub const fn to_f32(self) -> f32 { | ||
let bits = self.0; | ||
let mask = ((bits >> 31) as u32) >> 1; | ||
let res = bits ^ (mask as i32); | ||
f32::from_bits(res as u32) | ||
} | ||
|
||
#[inline(always)] | ||
pub const fn to_i32(self) -> i32 { | ||
self.0 | ||
} | ||
} | ||
|
||
impl From<f32> for Distance { | ||
#[inline(always)] | ||
fn from(value: f32) -> Self { | ||
Distance::from_f32(value) | ||
} | ||
} | ||
|
||
impl From<Distance> for f32 { | ||
#[inline(always)] | ||
fn from(value: Distance) -> Self { | ||
Distance::to_f32(value) | ||
} | ||
} | ||
|
||
#[test] | ||
fn distance_conversions() { | ||
assert_eq!(Distance::from(0.0f32), Distance::ZERO); | ||
assert_eq!(Distance::from(f32::INFINITY), Distance::INFINITY); | ||
assert_eq!(Distance::from(f32::NEG_INFINITY), Distance::NEG_INFINITY); | ||
for i in -100..100 { | ||
let val = (i as f32) * 0.1; | ||
assert_eq!(f32::from(Distance::from(val)).to_bits(), val.to_bits()); | ||
} | ||
assert_eq!( | ||
f32::from(Distance::from(0.0f32)).to_bits(), | ||
0.0f32.to_bits() | ||
); | ||
assert_eq!( | ||
f32::from(Distance::from(-0.0f32)).to_bits(), | ||
(-0.0f32).to_bits() | ||
); | ||
assert_eq!( | ||
f32::from(Distance::from(f32::NAN)).to_bits(), | ||
f32::NAN.to_bits() | ||
); | ||
assert_eq!( | ||
f32::from(Distance::from(-f32::NAN)).to_bits(), | ||
(-f32::NAN).to_bits() | ||
); | ||
assert_eq!( | ||
f32::from(Distance::from(f32::INFINITY)).to_bits(), | ||
f32::INFINITY.to_bits() | ||
); | ||
assert_eq!( | ||
f32::from(Distance::from(-f32::INFINITY)).to_bits(), | ||
(-f32::INFINITY).to_bits() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "rabitq" | ||
version.workspace = true | ||
edition.workspace = true | ||
|
||
[dependencies] | ||
distance = { path = "../distance" } | ||
simd = { path = "../simd" } | ||
|
||
[lints] | ||
workspace = true |
Oops, something went wrong.