Code/Util/IdentifierDisjunctor.cs
namespace Nodebox.Util;

public class IdentifierDisjunctor(string separator = "'") {
    public readonly static IdentifierDisjunctor Bypass = new BypassIdentifierDisjunctor();
    private class BypassIdentifierDisjunctor : IdentifierDisjunctor {
        public override string Process(string s) => s;
    }

    protected string Separator { get; set; } = separator;
    protected Dictionary<string, ulong> Store { get; set; } = [];

    public string this[string s] {
        get => Process(s);
    }

    public virtual string Process(string s) {
        if (Store.TryGetValue(s, out var generation)) {
            generation += 1;
            Store[s] = generation;
        } else {
            generation = 0;
            Store[s] = generation;
        }

        return $"{s}{Separator}{generation}";
    }
}