-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic Data Structures #33
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, added few initial comments.
09bcd6a
to
50c0649
Compare
d0d92a5
to
b0b97bd
Compare
We may need to use ordered maps instead of hash maps, so the lists of partitions are consistently ordered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few more questions and comments
Signed-off-by: Elazar Gershuni <[email protected]>
Signed-off-by: Elazar Gershuni <[email protected]>
Also, rename NewMap to NewHashMap Signed-off-by: Elazar Gershuni <[email protected]>
Signed-off-by: Elazar Gershuni <[email protected]>
Added an elaborated README, and changed implementation of MultiMap to use HashSet. |
BTW, I think the class ICMP is better named ICMPRule, and is a set. The file icmp.go in the netp package should only have functions that are related to ICMP proper. Such change would also solve the need to expose implementation details of the ICMP class to the ICMPSet class. |
@adisos is there anything left for me to implement/document so this PR can be merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few small comments and questions
return m.m.IsEmpty() | ||
} | ||
|
||
// Size returns the number of unique pairs in the Product object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the Size documentation is incorrect? it does not return the number of pairs..
// Product is a cartesian product of sets S1 x S2 | ||
type Product[S1 Set[S1], S2 Set[S2]] interface { | ||
Set[Product[S1, S2]] | ||
Partitions() []Pair[S1, S2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partitions() []Pair[S1, S2] | |
// Partitions returns a slice of pairs in the product set (note that the order is arbitrary) | |
Partitions() []Pair[S1, S2] |
type Product[S1 Set[S1], S2 Set[S2]] interface { | ||
Set[Product[S1, S2]] | ||
Partitions() []Pair[S1, S2] | ||
NumPartitions() int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should explain the difference between NumPartitions
and Size
?
Set[Product[S1, S2]] | ||
Partitions() []Pair[S1, S2] | ||
NumPartitions() int | ||
Left(empty S1) S1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left(empty S1) S1 | |
// Left returns the left projection from pairs in the product set on S1, given input of an empty set in S1 | |
Left(empty S1) S1 |
Partitions() []Pair[S1, S2] | ||
NumPartitions() int | ||
Left(empty S1) S1 | ||
Right(empty S2) S2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right(empty S2) S2 | |
// Right returns the right projection from pairs in the product set S2, given input of an empty set in S2 | |
Right(empty S2) S2 |
NumPartitions() int | ||
Left(empty S1) S1 | ||
Right(empty S2) S2 | ||
Swap() Product[S2, S1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swap() Product[S2, S1] | |
// Swap returns a new Product object, built from the input object, with left and right swapped | |
Swap() Product[S2, S1] |
added few small comments, still reviewing the tests and some implementation details. |
Co-authored-by: Adi Sosnovich <[email protected]>
Signed-off-by: Elazar Gershuni <[email protected]>
interval: * Separate tests from interval_test.go * Improve documentation. * Export and set-like functions that are well defined. * Rename interval.Subtract to interval.SubtractSplit, and add tests. * Handle empty cases first. * Preallocate Elements. intervalset: * Guard Size() from overflow, and use intervalset.CalculateSize(). * Handle empty cases first. * Remove String() method, since it is not obvious; clients should implement. Signed-off-by: Elazar Gershuni <[email protected]>
I've improved and fixed the documentation of interface.go. @adisos please re-review this part. Additionally, I've improved the interval package. interval:
intervalset:
I think it's better to make |
Decompose the data structures into domain-specific and generic data structures.
The
ds
package has zero dependencies, and it knows nothing about numbers or network.Interfaces (all in
interfaces.go
):Implementations:
HashMap
- a simple adapter around a go map, allowingHashable
keys.HashSet
MultiMap
is a non-injective map. It gives a simple "inverse" on a HashMap.ProductLeft
and ProductRightis a map-based implementation of a cartesian product; it implementsProduct
as a one-to-one mapping from sets to sets, where each key-value pairs encodes the cross product of its two items.TripleSetLeft
andTripleSetRight
andTripleSetOuter
are right-, left- and outer-associative implementations ofTripleSet
.DisjointSum
is tagged-union of two sets. Go's generics place some limitations on the implementation; The empty element must always be explicitly passed to the constructor.UnitSet
is an idea - using sets of size 1 as the identity element of Product. It's probably not really helpful.The
interval
package hasinterval
andintervalset
. Nothing particularly new about them.netp
is unchanged.The
netset
package is where handles sets of network elements.ICMPSet
is largely the one proposed in Add ICMP set #23.IPBlock
is adapted to implementSet
.TCPUDPSet
is aTripleSet
ofProtocolSet
xPortSet
xPortSet
TransportSet
is a disjoint union ofTCPUDPSet
+ICMPSet
ConnectionSet
is aTripleSet
ofIPBlock
xIPBlock
xTransportSet
The package
connection
now contains the state-aware connectionset (namedSet
), and its json-formatting. In my opinion it should be moved to the analyzer.Many tests are adapted.
but some data structures do not have dedicated tests.There is no implementation of a dynamically-bounded tuple, since I could not find the proper way to fit that into a generic datastructure with a well defined degenerate edge case.
The diff is probably not useful; it should be easier to read the code.