Skip to content

Feat: ArrayOfNumber Tuple Sketch #79

@proost

Description

@proost

Summary

Add Go version ArrayOfDouble Tuple Sketch.

Design

ArrayOfDouble Tuple Sketch

// Number constraint for types that can be used in ArrayOfNumberSummary.
// NOTE: Only allowed fixed-size type.
type Number interface {
	~int8 | ~int16 | ~int32 | ~int64 |
		~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64
}

type ArrayOfNumberSketch[V Number] interface {
	Sketch[*ArrayOfNumberSummary[V]]

	// NumValuesInSummary returns the number of values in ArrayOfNumberSummary.
	NumValuesInSummary() uint8
}

// ArrayOfNumberSummary is a fixed-size array of numeric values used as a summary in tuple sketches.
type ArrayOfNumberSummary[T Number] struct {
	values []T
	size   uint8
}

// Reset clears the content of the summary, restoring it to its initial state.
func (s *ArrayOfNumberSummary[T]) Reset()

// Clone creates and returns a deep copy of the current Summary instance.
func (s *ArrayOfNumberSummary[T]) Clone() Summary

// Update incorporates a new value into the summary, modifying its internal state based on the given input value.
func (s *ArrayOfNumberSummary[T]) Update(values []T)

// Values returns the values in the summary.
func (s *ArrayOfNumberSummary[T]) Values() []T

I’ve found that ArrayOfDouble sketch can be numeric array sketch. So i expand original one. Because of serialization, i decide to accept fixed size number type element array.

  • ArrayOfNumberSketch inherit and extend Sketch to support numeric array summary sketch.
  • ArrayOfNumberSummary will do same thing ArrayOfDouble Sketch Summary. So will add given values when Update method is called.

ArrayOfNumberUpdateSketch

// ArrayOfNumberUpdateSketch builds Tuple sketch from input data via update methods.
// This is a wrapper around a tuple sketch to match the functionality
// and serialization format of ArrayOfDoublesSketch in Java.
type ArrayOfNumberUpdateSketch[V Number] struct {
	table                   *hashtable[*ArrayOfNumberSummary[V]]
	numberOfValuesInSummary uint8
}

ArrayOfNumberUpdateSketch implements ArrayOfNumberSketch

ArrayOfNumberCompactSketch

// ArrayOfNumberCompactSketch is the immutable, serializable form of an array of number tuple sketch.
type ArrayOfNumberCompactSketch[V Number] struct {
	theta                   uint64
	entries                 []entry[*ArrayOfNumberSummary[V]]
	seedHash                uint16
	numberOfValuesInSummary uint8
	isEmpty                 bool
	isOrdered               bool
}
  • ArrayOfNumberCompactSketch implements ArrayOfNumberSketch
  • serialization and deserialization follows encoder & decoder pattern.

Release Schedule

I will upload 3 PRs.

  1. A PR for ArrayOfNumberUpdateSketch and interfaces.
  2. A PR for ArrayOfNumberCompactSketch and serialization / deserialization.
  3. Set Operations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions