Click here to Skip to main content
15,890,845 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.

 
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 
ok, untested code (sorry) but I think it should work, in principle...
C#
public 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)
    {
        if (max < min)
            throw new ArgumentOutOfRangeException(nameof(max));
        Min = min;
        Max = max;
        To = to;
    }
    public FATransition(FA to)
    {
        Min = Max = -1;
        To = to;
    }
    public int CompareTo(FATransition other)
    {
        var c = Min.CompareTo(other.Min);
        if (c != 0) return c;
        return Max.CompareTo(other.Max);
    }
}
public class FA : ICollection<FATransition>
{
    List<FATransition> _transitions = new List<FATransition>();

    public bool IsDeterministic { get; private set; } = true;

    int FindIndex(int min)
    {
        int iMin = 0, iMax = _transitions.Count;
        while (iMin + 1 < iMax)
        {
            int i = (iMin + iMax) / 2;
            var t = _transitions[i];

            if (t.Min >= min)
                iMax = i;
            else
                iMin = i;
        }
        return iMin;
    }

    public void Add(FATransition item)
    {
        int start = FindIndex(item.Min);
        for (int i = _transitions.Count - 1; i >= start; i--)
        {
            var t = _transitions[i];
            if (t.To == item.To && t.Min <= item.Max)
            {
                item.Max = t.Max;
                _transitions.RemoveAt(i);
            }
            else if (t.To != item.To && t.Min <= item.Max && t.Max > item.Min)
            {
                IsDeterministic = false;
            }
        }
        _transitions.Insert(start, item);
    }

    bool ICollection<FATransition>.Remove(FATransition item)
        => throw new NotSupportedException();

    public int Count => _transitions.Count;

    bool ICollection<FATransition>.IsReadOnly => false;

    public void Clear()
    {
        _transitions.Clear();
        IsDeterministic = true;
    }

    public bool Contains(FATransition item) => _transitions.Contains(item);

    public void CopyTo(FATransition[] array, int arrayIndex)
        => _transitions.CopyTo(array, arrayIndex);

    public IEnumerator<FATransition> GetEnumerator() => _transitions.GetEnumerator();

    IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
A new .NET Serializer
All in one Menu-Ribbon Bar
Taking over the world since 1371!


modified 30-Dec-21 16:27pm.

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 
GeneralRe: My brain hurts: overlapping range lists Pin
Gerry Schmitz30-Dec-21 10:05
mveGerry Schmitz30-Dec-21 10:05 
GeneralRe: My brain hurts: overlapping range lists Pin
honey the codewitch30-Dec-21 11:14
mvahoney the codewitch30-Dec-21 11:14 
GeneralRe: My brain hurts: overlapping range lists Pin
0x01AA30-Dec-21 11:20
mve0x01AA30-Dec-21 11:20 
GeneralRe: My brain hurts: overlapping range lists Pin
honey the codewitch30-Dec-21 11:37
mvahoney the codewitch30-Dec-21 11:37 
GeneralRe: My brain hurts: overlapping range lists Pin
Gerry Schmitz30-Dec-21 19:06
mveGerry Schmitz30-Dec-21 19:06 
GeneralRe: My brain hurts: overlapping range lists Pin
Randor 30-Dec-21 11:49
professional Randor 30-Dec-21 11:49 
GeneralRe: My brain hurts: overlapping range lists Pin
honey the codewitch30-Dec-21 12:05
mvahoney the codewitch30-Dec-21 12:05 
GeneralRe: My brain hurts: overlapping range lists Pin
englebart1-Jan-22 9:11
professionalenglebart1-Jan-22 9:11 
JokeWhat spice does Satan use..–––––WARNING: WILL CAUSE EYE ROLLING... Sorry the last one was so late yesterday... Pin
oofalladeez34330-Dec-21 7:49
professionaloofalladeez34330-Dec-21 7:49 

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.