Click here to Skip to main content
15,558,870 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 12:52
Super Lloyd30-Dec-21 12:52 
AnswerRe: Multiple Desktop Pin
Peter_in_278030-Dec-21 14:59
professionalPeter_in_278030-Dec-21 14:59 
GeneralRe: Multiple Desktop Pin
Super Lloyd30-Dec-21 18:01
Super Lloyd30-Dec-21 18:01 
GeneralRe: Multiple Desktop Pin
Peter_in_278030-Dec-21 18:37
professionalPeter_in_278030-Dec-21 18:37 
AnswerRe: Multiple Desktop Pin
theoldfool30-Dec-21 15:05
professionaltheoldfool30-Dec-21 15:05 
GeneralRe: Multiple Desktop Pin
Super Lloyd30-Dec-21 18:00
Super Lloyd30-Dec-21 18:00 
GeneralRe: Multiple Desktop Pin
theoldfool31-Dec-21 1:43
professionaltheoldfool31-Dec-21 1:43 
RantMy brain hurts: overlapping range lists Pin
honey the codewitch30-Dec-21 9:08
mvahoney the codewitch30-Dec-21 9: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 9:19
professional0x01AA30-Dec-21 9:19 
GeneralRe: My brain hurts: overlapping range lists Pin
oofalladeez34330-Dec-21 9:33
professionaloofalladeez34330-Dec-21 9:33 
GeneralRe: My brain hurts: overlapping range lists Pin
ElectronProgrammer30-Dec-21 10:10
ElectronProgrammer30-Dec-21 10:10 
GeneralRe: My brain hurts: overlapping range lists Pin
honey the codewitch30-Dec-21 10:34
mvahoney the codewitch30-Dec-21 10:34 
GeneralRe: My brain hurts: overlapping range lists Pin
ElectronProgrammer30-Dec-21 11:35
ElectronProgrammer30-Dec-21 11:35 
GeneralRe: My brain hurts: overlapping range lists Pin
honey the codewitch30-Dec-21 12:18
mvahoney the codewitch30-Dec-21 12:18 
GeneralRe: My brain hurts: overlapping range lists Pin
Super Lloyd30-Dec-21 10:30
Super Lloyd30-Dec-21 10:30 
GeneralRe: My brain hurts: overlapping range lists Pin
honey the codewitch30-Dec-21 10:32
mvahoney the codewitch30-Dec-21 10:32 
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 12:17
mvahoney the codewitch30-Dec-21 12:17 
GeneralRe: My brain hurts: overlapping range lists Pin
Super Lloyd30-Dec-21 12:22
Super Lloyd30-Dec-21 12:22 
GeneralRe: My brain hurts: overlapping range lists Pin
honey the codewitch30-Dec-21 12:32
mvahoney the codewitch30-Dec-21 12:32 
GeneralRe: My brain hurts: overlapping range lists Pin
Super Lloyd30-Dec-21 12:36
Super Lloyd30-Dec-21 12:36 
GeneralRe: My brain hurts: overlapping range lists Pin
Super Lloyd30-Dec-21 11:29
Super Lloyd30-Dec-21 11:29 
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
Gerry Schmitz30-Dec-21 10:51
mveGerry Schmitz30-Dec-21 10:51 
GeneralRe: My brain hurts: overlapping range lists Pin
honey the codewitch30-Dec-21 10:55
mvahoney the codewitch30-Dec-21 10: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.