np-guard / models

Models for connectivity and network resources
https://pkg.go.dev/github.com/np-guard/models
Apache License 2.0
1 stars 0 forks source link

Generic Data Structures #33

Open elazarg opened 2 months ago

elazarg commented 2 months ago

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:

The interval package has interval and intervalset. Nothing particularly new about them.

netp is unchanged.

The netset package is where handles sets of network elements.

The package connection now contains the state-aware connectionset (named Set), 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.

elazarg commented 3 weeks ago

We may need to use ordered maps instead of hash maps, so the lists of partitions are consistently ordered.

elazarg commented 2 weeks ago

Added an elaborated README, and changed implementation of MultiMap to use HashSet.

elazarg commented 2 weeks ago

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.

elazarg commented 1 week ago

@adisos is there anything left for me to implement/document so this PR can be merged?

adisos commented 3 days ago

@adisos is there anything left for me to implement/document so this PR can be merged?

added few small comments, still reviewing the tests and some implementation details.

elazarg commented 3 days ago

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 GenericInterval and GenericCanonicalSet as generic types (with integral constraints), so clients can choose whether or not to rely on things like Size() being 64bit integer. interval.Interval should be an alias to GenericInterval[int], and interval.Set should be an alias to GenericCanonicalSet[int].