Note: this is unrelated to the concurrency problem of mutual exclusion, but I couldn't think of a better way of describing the problem.
I have a problem that I have a case where I want to let a user select some flags, but some flags are mutually exclusive. I want to describe which flags are mutually exclusive using a data structure, but everything I've thought of has been clunky.
Basically, I want to be able to specify how flags will be used like so:
[ -fa | -e | -d ] [ -c ] [ -g | -h ]
This should semantically mean, I can have any one of -fa, -e, -d, but not two or more (however, f can be used with a, and you don't need to use both). I can either have a -c or not, and I can have either -g or -h, but not both.
Here's my "best" solution.
Map[Flag, MutexGroup] (and its inverse, Map[MutexGroup, List[Flag]]) Map[MutexGroup, List[MutexGroup]]
What it would look like for my example would be
Map("f" -> 1, "a" -> 1, "e" -> 2, "d" -> 3, "c" -> 4, "g" -> 5, "h" -> 6) Map(1 -> List(2, 3), 2 -> List(1, 3), 3 -> List(1, 2), 4 -> List.empty, 5 -> List(6), 6 -> List(5))
I haven't included the Map[MutexGroup, List[Flag]] for brevity.
This solution makes me shudder just thinking about having to work with it. Is there a canonical way for dealing with this kind of thing?