Skip to content

Commit d209b3c

Browse files
committed
feat: imple densitysketch
Signed-off-by: Chojan Shang <psiace@apache.org>
1 parent 1640af4 commit d209b3c

5 files changed

Lines changed: 868 additions & 0 deletions

File tree

datasketches/src/density/mod.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
//! Density sketch implementation for density estimation from streaming data.
19+
//!
20+
//! The sketch maintains a coreset of points using a compaction scheme and
21+
//! provides density estimates at query points via a kernel function.
22+
//!
23+
//! # Usage
24+
//!
25+
//! ```rust
26+
//! # use datasketches::density::DensitySketch;
27+
//! let mut sketch: DensitySketch<f64> = DensitySketch::new(10, 3);
28+
//! sketch.update(vec![0.0, 0.0, 0.0]);
29+
//! sketch.update(vec![1.0, 2.0, 3.0]);
30+
//! let estimate = sketch.estimate(&[0.0, 0.0, 0.0]);
31+
//! assert!(estimate > 0.0);
32+
//! ```
33+
34+
mod serialization;
35+
mod sketch;
36+
37+
pub use self::sketch::DensityItem;
38+
pub use self::sketch::DensityKernel;
39+
pub use self::sketch::DensitySketch;
40+
pub use self::sketch::DensityValue;
41+
pub use self::sketch::GaussianKernel;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
pub(super) const PREAMBLE_INTS_SHORT: u8 = 3;
19+
pub(super) const PREAMBLE_INTS_LONG: u8 = 6;
20+
pub(super) const SERIAL_VERSION: u8 = 1;
21+
pub(super) const DENSITY_FAMILY_ID: u8 = 19;
22+
pub(super) const FLAGS_IS_EMPTY: u8 = 1 << 2;

0 commit comments

Comments
 (0)