11package cardinality
22
3- type ProviderConstructor [T uint32 | uint64 ] func () Provider [T ]
3+ type ProviderConstructor [T uint32 | uint64 ] func () MutableProvider [T ]
44type SimplexConstructor [T uint32 | uint64 ] func () Simplex [T ]
55type DuplexConstructor [T uint32 | uint64 ] func () Duplex [T ]
66
7- // Provider describes the most basic functionality of a cardinality provider algorithm: adding elements to the provider
8- // and producing the cardinality of those elements.
97type Provider [T uint32 | uint64 ] interface {
10- Add (value ... T )
11- Or (other Provider [T ])
12- Clear ()
138 Cardinality () uint64
9+ Clone () Provider [T ]
1410}
1511
16- func CloneProvider [T uint32 | uint64 ](provider Provider [T ]) Provider [T ] {
17- switch typedProvider := provider .(type ) {
18- case Simplex [T ]:
19- return typedProvider .Clone ()
20-
21- case Duplex [T ]:
22- return typedProvider .Clone ()
12+ // MutableProvider describes the most basic functionality of a cardinality provider algorithm: adding elements to the provider
13+ // and producing the cardinality of those elements.
14+ type MutableProvider [T uint32 | uint64 ] interface {
15+ Provider [T ]
2316
24- default :
25- return provider
26- }
17+ Add (value ... T )
18+ Clear ()
2719}
2820
2921// Simplex is a one-way cardinality provider that does not allow a user to retrieve encoded values back out of the
3022// provider. This interface is suitable for algorithms such as HyperLogLog which utilizes a hash function to merge
3123// identifiers into the cardinality provider.
3224type Simplex [T uint32 | uint64 ] interface {
33- Provider [T ]
25+ MutableProvider [T ]
3426
35- Clone () Simplex [T ]
27+ Or ( other Provider [T ])
3628}
3729
3830// Iterator allows enumeration of a duplex cardinality provider without requiring the allocation of the provider's set.
@@ -44,15 +36,24 @@ type Iterator[T uint32 | uint64] interface {
4436// Duplex is a two-way cardinality provider that allows a user to retrieve encoded values back out of the provider. This
4537// interface is suitable for algorithms that behave similar to bitvectors.
4638type Duplex [T uint32 | uint64 ] interface {
47- Provider [T ]
39+ MutableProvider [T ]
4840
41+ Or (other Provider [T ])
4942 Xor (other Provider [T ])
5043 And (other Provider [T ])
5144 AndNot (other Provider [T ])
45+
46+ CheckedAdd (value T ) bool
5247 Remove (value T )
48+ Contains (value T ) bool
49+ Slice () []T
50+ Each (delegate func (value T ) bool )
51+ }
52+
53+ type ImmutableDuplex [T uint32 | uint64 ] interface {
54+ Provider [T ]
55+
5356 Slice () []T
5457 Contains (value T ) bool
5558 Each (delegate func (value T ) bool )
56- CheckedAdd (value T ) bool
57- Clone () Duplex [T ]
5859}
0 commit comments