pub trait MedianStore<KeyPrefix: FullCodec, MedianValue: Average + LexicographicEncoding> {
type Length: StorageMap<KeyPrefix, u64, Query = u64>;
type Store: IterableStorageDoubleMap<KeyPrefix, MedianValue::Encoding, u64, Query = u64>;
type ReverseStore: IterableStorageDoubleMap<KeyPrefix, LexicographicReverse<MedianValue>, (), Query = ()>;
type Position: StorageMap<KeyPrefix, u64, Query = Option<u64>>;
type Median: StorageMap<KeyPrefix, MedianValue, Query = Option<MedianValue>>;
const POLICY: Policy;
}Expand description
The store for a median.
KeyPrefix is accepted so a single set of storage values may be used to back multiple medians.
For all StorageDoubleMaps however, the hasher of the second key MUST be the identity hasher.
For all storage values present, they MUST be considered opaque to the caller and left undisturbed. No assumptions may be made about their internal representation nor usage. Any names or documentation comments are solely for the review of the implementation itself, and are not intended to signify any potential layout nor use cases to the caller. ANY external usage has undefined behavior.
Required Associated Constants§
Required Associated Types§
Sourcetype Length: StorageMap<KeyPrefix, u64, Query = u64>
type Length: StorageMap<KeyPrefix, u64, Query = u64>
The amount of items currently present within the median’s list.
Sourcetype Store: IterableStorageDoubleMap<KeyPrefix, MedianValue::Encoding, u64, Query = u64>
type Store: IterableStorageDoubleMap<KeyPrefix, MedianValue::Encoding, u64, Query = u64>
A store for the values currently present within the median.
The value is the amount of instances of this value within the median’s list.
Sourcetype ReverseStore: IterableStorageDoubleMap<KeyPrefix, LexicographicReverse<MedianValue>, (), Query = ()>
type ReverseStore: IterableStorageDoubleMap<KeyPrefix, LexicographicReverse<MedianValue>, (), Query = ()>
A secondary store for the values currently present within the median.
Sourcetype Position: StorageMap<KeyPrefix, u64, Query = Option<u64>>
type Position: StorageMap<KeyPrefix, u64, Query = Option<u64>>
The position of the saved median within the list of values.
This is necessary as when a value selected as the current median is present multiple times within the list of values, the code does not know which instance was selected as the median, as necessary to know when to advance to a lesser/greater value. To resolve this, once we know a value is the median value, we always set the position to the first instance of the value. This gives us a consistent frame of reference to decide the next steps of the algorithm upon.
Sourcetype Median: StorageMap<KeyPrefix, MedianValue, Query = Option<MedianValue>>
type Median: StorageMap<KeyPrefix, MedianValue, Query = Option<MedianValue>>
The median value.
This may drift from the actual median while an update is performed.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.