iotaledger / hive.go

A Go library containing data structures, various utils and abstractions which are used by both GoShimmer and Hornet.
Apache License 2.0
61 stars 24 forks source link

Feat: Added reactive SortedSet #630

Closed hmoog closed 9 months ago

hmoog commented 10 months ago

Description of change

This PR introduces a reactive SortedSet, which extends the capabilities of the Set to derive a perception of weight and order for its elements.

We expose the information through the following additional API endpoints:

// SortedSet is a reactive Set implementation that allows consumers to subscribe to its changes 
// and that keeps a sorted perception of its elements.
type SortedSet[ElementType comparable] interface {
    // Set imports the methods of the Set interface.
    Set[ElementType]

    // Ascending returns a slice of all elements of the set in ascending order.
    Ascending() []ElementType

    // Descending returns a slice of all elements of the set in descending order.
    Descending() []ElementType

    // HeaviestElement returns the element with the heaviest weight.
    HeaviestElement() ReadableVariable[ElementType]

    // LightestElement returns the element with the lightest weight.
    LightestElement() ReadableVariable[ElementType]
}

Type of change

Change checklist