[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Mutable/Frozen MH in FFI #2728

Draft
wants to merge 1 commit into
base: latest
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/sourmash.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ double kmerminhash_similarity(const SourmashKmerMinHash *ptr,

void kmerminhash_slice_free(uint64_t *ptr, uintptr_t insize);

SourmashKmerMinHash *kmerminhash_to_frozen(const SourmashKmerMinHash *ptr);

SourmashKmerMinHash *kmerminhash_to_mutable(const SourmashKmerMinHash *ptr);

bool kmerminhash_track_abundance(const SourmashKmerMinHash *ptr);

void nodegraph_buffer_free(uint8_t *ptr, uintptr_t insize);
Expand Down Expand Up @@ -370,16 +374,12 @@ SourmashStr signature_get_filename(const SourmashSignature *ptr);

SourmashStr signature_get_license(const SourmashSignature *ptr);

SourmashKmerMinHash **signature_get_mhs(const SourmashSignature *ptr, uintptr_t *size);

SourmashStr signature_get_name(const SourmashSignature *ptr);

uintptr_t signature_len(const SourmashSignature *ptr);

SourmashSignature *signature_new(void);

void signature_push_mh(SourmashSignature *ptr, const SourmashKmerMinHash *other);

SourmashStr signature_save_json(const SourmashSignature *ptr);

void signature_set_filename(SourmashSignature *ptr, const char *name);
Expand Down
12 changes: 6 additions & 6 deletions src/core/src/ffi/hyperloglog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::prelude::*;
use crate::signature::SigsTrait;
use crate::sketch::hyperloglog::HyperLogLog;

use crate::ffi::minhash::SourmashKmerMinHash;
use crate::ffi::minhash::{MinHash, SourmashKmerMinHash};
use crate::ffi::utils::ForeignObject;

pub struct SourmashHyperLogLog;
Expand Down Expand Up @@ -108,14 +108,14 @@ unsafe fn hll_merge(
}

ffi_fn! {
unsafe fn hll_update_mh(
ptr: *mut SourmashHyperLogLog,
optr: *const SourmashKmerMinHash,
) {
unsafe fn hll_update_mh(ptr: *mut SourmashHyperLogLog, optr: *const SourmashKmerMinHash) {
let hll = SourmashHyperLogLog::as_rust_mut(ptr);
let mh = SourmashKmerMinHash::as_rust(optr);

mh.update(hll)?
match mh {
MinHash::Mutable(mh) => mh.update(hll)?,
MinHash::Frozen(mh) => mh.update(hll)?,
}
}
}

Expand Down
22 changes: 13 additions & 9 deletions src/core/src/ffi/index/revindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::sketch::minhash::KmerMinHash;
use crate::sketch::Sketch;

use crate::ffi::index::SourmashSearchResult;
use crate::ffi::minhash::SourmashKmerMinHash;
use crate::ffi::minhash::{MinHash, SourmashKmerMinHash};
use crate::ffi::signature::SourmashSignature;
use crate::ffi::utils::{ForeignObject, SourmashStr};

Expand Down Expand Up @@ -43,7 +43,7 @@ unsafe fn revindex_new_with_paths(
let template = {
assert!(!template_ptr.is_null());
//TODO: avoid clone here
Sketch::MinHash(SourmashKmerMinHash::as_rust(template_ptr).clone())
SourmashKmerMinHash::as_rust(template_ptr).clone().into()
};

let queries_vec: Vec<KmerMinHash>;
Expand All @@ -52,9 +52,11 @@ unsafe fn revindex_new_with_paths(
} else {
queries_vec = slice::from_raw_parts(queries_ptr, inqueries)
.iter()
.map(|mh_ptr|
// TODO: avoid this clone
SourmashKmerMinHash::as_rust(*mh_ptr).clone())
.map(|mh_ptr| match SourmashKmerMinHash::as_rust(*mh_ptr) {
// TODO: avoid this clone
MinHash::Mutable(mh) => mh.clone().into(),
MinHash::Frozen(mh) => mh.clone(),
})
.collect();
Some(queries_vec.as_ref())
};
Expand Down Expand Up @@ -90,7 +92,7 @@ unsafe fn revindex_new_with_sigs(
let template = {
assert!(!template_ptr.is_null());
//TODO: avoid clone here
Sketch::MinHash(SourmashKmerMinHash::as_rust(template_ptr).clone())
SourmashKmerMinHash::as_rust(template_ptr).clone().into()
};

let queries_vec: Vec<KmerMinHash>;
Expand All @@ -99,9 +101,11 @@ unsafe fn revindex_new_with_sigs(
} else {
queries_vec = slice::from_raw_parts(queries_ptr, inqueries)
.iter()
.map(|mh_ptr|
// TODO: avoid this clone
SourmashKmerMinHash::as_rust(*mh_ptr).clone())
.map(|mh_ptr| match SourmashKmerMinHash::as_rust(*mh_ptr) {
// TODO: avoid this clone
MinHash::Mutable(mh) => mh.clone().into(),
MinHash::Frozen(mh) => mh.clone(),
})
.collect();
Some(queries_vec.as_ref())
};
Expand Down
Loading