sybila / biodivine-lib-param-bn

Rust library for working with parametrised Boolean networks.
MIT License
2 stars 2 forks source link

New, safer identifier system #47

Open daemontus opened 9 months ago

daemontus commented 9 months ago

Right now, Id objects are just indices. As such, the same ID object is valid in two different BooleanNetwork objects. This can lead to accidents if multiple networks are used in the same context.

A possible way to fix this is to add a randomized usize "seed" to each BN object, and then xor this seed with every index to produce an ID. We can then xor the ID with the seed again to decode the original index. If the ID is produced using a different "seed", it is extremely likely that this decoding will produce an index which is not valid in this particular BN.

daemontus commented 9 months ago

Note that this approach has the issue that larger networks have a bigger chance of collision, since fewer bits are used for the seed. Alternatively, we could just use u64 instead of usize and then use upper 32 bits for the seed and lower 32 bits for variable index. This would limit us to 2^32 variables, but that is more than enough at this point.