Click here to Skip to main content
15,899,935 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
QuestionMultiple Desktop Pin
Super Lloyd30-Dec-21 11:52
Super Lloyd30-Dec-21 11:52 
AnswerRe: Multiple Desktop Pin
Peter_in_278030-Dec-21 13:59
professionalPeter_in_278030-Dec-21 13:59 
GeneralRe: Multiple Desktop Pin
Super Lloyd30-Dec-21 17:01
Super Lloyd30-Dec-21 17:01 
GeneralRe: Multiple Desktop Pin
Peter_in_278030-Dec-21 17:37
professionalPeter_in_278030-Dec-21 17:37 
AnswerRe: Multiple Desktop Pin
theoldfool30-Dec-21 14:05
professionaltheoldfool30-Dec-21 14:05 
GeneralRe: Multiple Desktop Pin
Super Lloyd30-Dec-21 17:00
Super Lloyd30-Dec-21 17:00 
GeneralRe: Multiple Desktop Pin
theoldfool31-Dec-21 0:43
professionaltheoldfool31-Dec-21 0:43 
RantMy brain hurts: overlapping range lists Pin
honey the codewitch30-Dec-21 8:08
mvahoney the codewitch30-Dec-21 8:08 
This is not a programming question. I will figure this out, and I don't really need help with it, although if an idea is burning a hole in your brain, go ahead and let me know.

I have the following structures:

C#
struct FATransition : IComparable<FATransition> {
    public int Min; // -1 for Epsilon
    public int Max; // -1 for Epsilon
    public FA To;
    public FATransition(int min,int max,FA to) {
        Min = min;
        Max = max;
        To = to;
    }
    public FATransition(FA to) {
        Min = Max = -1;
        To = to;
    }
    public int CompareTo([AllowNull] FATransition other) {
        var c = Min.CompareTo(other.Min);
        if (c != 0) return c;
        return Max.CompareTo(other.Max);
    }
}
...
class FA {
...
    public bool IsDeterministic { get; private set; } = true;
    List<FATransition> _transitions = new List<FATransition>();
    public IList<FATransition> Transitions { get { return _transitions.AsReadOnly(); } }
...
}


The upshot is _transitions contains a list of range+state pairs.

The list should be sorted at all times, meaning inserts should be sorted. There will not be a way to remove FATransition items, except for clearing the list altogether, I think? I'm not sure yet. If I can avoid it I will.

There's a wrinkle. The ranges should not overlap for FATransitions where the To state is the same. On insert, they need to be merged into one transition if they overlap.

If there ever ends up a situation where more than one range or part of a range points to more than one To state I mark the IsDeterministic property false.

It's not that I don't know how to do this - it's just that there's no clean way to do it that is also efficient.

If I simply collated and merged over the entire list and rebuilt the list on each insert, that wouldn't be much code.

But to do it inline, only messing with the parts of the list that need messed with is corner case city.

I hate corner cases.

A) It broadens the test matrix
B) It is often *hard* to get full code coverage the more corner cases you have
C) It's harder to write
D) Ergo it's harder to read
E) 9 times out of 10 it's due to an anti-pattern

In this case, it's not an anti-pattern, or at least not one I can readily identify. It's just complicated. Dealing with sorted inserts is not a problem, but dealing with sorted range inserts gets tricky. The naive way to do it is to "expand" the ranges into individual items so 0-9 would be 10 entries, and then work with that, recombining when done, but that's not efficient.

By itself, that's not terrible. But when you add the rules about the ranges being able to overlap as long as their destination (To) states are different it gets weird fast.

I hate code like this. I hate writing it, and I hate that I want to put it off so badly that I write posts like this.

I only hope getting this out there inspires me to somehow come up with a better way to skin this particular cat. Sometimes just writing out my frustration brings me answers.
Real programmers use butterflies

RantRe: My brain hurts: overlapping range lists Pin
0x01AA30-Dec-21 8:19
mve0x01AA30-Dec-21 8:19 
GeneralRe: My brain hurts: overlapping range lists Pin
oofalladeez34330-Dec-21 8:33
professionaloofalladeez34330-Dec-21 8:33 
GeneralRe: My brain hurts: overlapping range lists Pin
ElectronProgrammer30-Dec-21 9:10
ElectronProgrammer30-Dec-21 9:10 
GeneralRe: My brain hurts: overlapping range lists Pin
honey the codewitch30-Dec-21 9:34
mvahoney the codewitch30-Dec-21 9:34 
GeneralRe: My brain hurts: overlapping range lists Pin
ElectronProgrammer30-Dec-21 10:35
ElectronProgrammer30-Dec-21 10:35 
GeneralRe: My brain hurts: overlapping range lists Pin
honey the codewitch30-Dec-21 11:18
mvahoney the codewitch30-Dec-21 11:18 
GeneralRe: My brain hurts: overlapping range lists Pin
Super Lloyd30-Dec-21 9:30
Super Lloyd30-Dec-21 9:30 
GeneralRe: My brain hurts: overlapping range lists Pin
honey the codewitch30-Dec-21 9:32
mvahoney the codewitch30-Dec-21 9:32 
GeneralRe: My brain hurts: overlapping range lists Pin
Super Lloyd30-Dec-21 10:22
Super Lloyd30-Dec-21 10:22 
GeneralRe: My brain hurts: overlapping range lists Pin
honey the codewitch30-Dec-21 11:17
mvahoney the codewitch30-Dec-21 11:17 
GeneralRe: My brain hurts: overlapping range lists Pin
Super Lloyd30-Dec-21 11:22
Super Lloyd30-Dec-21 11:22 
GeneralRe: My brain hurts: overlapping range lists Pin
honey the codewitch30-Dec-21 11:32
mvahoney the codewitch30-Dec-21 11:32 
GeneralRe: My brain hurts: overlapping range lists Pin
Super Lloyd30-Dec-21 11:36
Super Lloyd30-Dec-21 11:36 
GeneralRe: My brain hurts: overlapping range lists Pin
Super Lloyd30-Dec-21 10:29
Super Lloyd30-Dec-21 10:29 
GeneralRe: My brain hurts: overlapping range lists Pin
ElectronProgrammer30-Dec-21 9:35
ElectronProgrammer30-Dec-21 9:35 
GeneralRe: My brain hurts: overlapping range lists Pin
Gerry Schmitz30-Dec-21 9:51
mveGerry Schmitz30-Dec-21 9:51 
GeneralRe: My brain hurts: overlapping range lists Pin
honey the codewitch30-Dec-21 9:55
mvahoney the codewitch30-Dec-21 9:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Straw Poll

Were you affected by the geomagnetic storms this past weekend?
Communication disruptions, electrified pipes, random unexplained blue-screens in Windows - the list of effects is terrifying.
  Results   479 votes