Example #1
0
 private PrefixCollection(
     Dictionary <FlagValue, AffixEntryGroup <PrefixEntry> > affixesByFlag,
     Dictionary <char, AffixEntryGroupCollection <PrefixEntry> > affixesByIndexedByKey,
     AffixEntryGroupCollection <PrefixEntry> affixesWithDots,
     AffixEntryGroupCollection <PrefixEntry> affixesWithEmptyKeys,
     FlagSet contClasses)
     : base(affixesByFlag, affixesByIndexedByKey, affixesWithDots, affixesWithEmptyKeys, contClasses)
 {
 }
Example #2
0
 internal AffixCollection(
     Dictionary <FlagValue, AffixEntryGroup <TEntry> > affixesByFlag,
     Dictionary <char, AffixEntryGroupCollection <TEntry> > affixesByIndexedByKey,
     AffixEntryGroupCollection <TEntry> affixesWithDots,
     AffixEntryGroupCollection <TEntry> affixesWithEmptyKeys,
     FlagSet contClasses)
 {
     AffixesByFlag         = affixesByFlag;
     AffixesByIndexedByKey = affixesByIndexedByKey;
     AffixesWithDots       = affixesWithDots;
     AffixesWithEmptyKeys  = affixesWithEmptyKeys;
     ContClasses           = contClasses;
     HasAffixes            = affixesByFlag.Count != 0;
 }
Example #3
0
        internal static TResult Create <TResult>(List <AffixEntryGroup <TEntry> .Builder> builders, Constructor <TResult> constructor)
            where TResult : AffixCollection <TEntry>
        {
            var affixesByFlag = new Dictionary <FlagValue, AffixEntryGroup <TEntry> >(builders.Count);
            var affixesByIndexedByKeyBuilders = new Dictionary <char, Dictionary <FlagValue, AffixEntryGroup <TEntry> .Builder> >();
            var affixesWithEmptyKeys          = new List <AffixEntryGroup <TEntry> >();
            var affixesWithDots = new List <AffixEntryGroup <TEntry> >();
            var contClasses     = new HashSet <FlagValue>();

            if (builders != null)
            {
                foreach (var builder in builders)
                {
                    var group = builder.ToGroup();
                    affixesByFlag.Add(group.AFlag, group);

                    var entriesWithNoKey = new List <TEntry>();
                    var entriesWithDots  = new List <TEntry>();

                    foreach (var entry in group.Entries)
                    {
                        var key = entry.Key;

                        contClasses.UnionWith(entry.ContClass);

                        if (string.IsNullOrEmpty(key))
                        {
                            entriesWithNoKey.Add(entry);
                        }
                        else if (key.Contains('.'))
                        {
                            entriesWithDots.Add(entry);
                        }
                        else
                        {
                            var indexedKey = key[0];
                            if (!affixesByIndexedByKeyBuilders.TryGetValue(indexedKey, out var keyedAffixes))
                            {
                                keyedAffixes = new Dictionary <FlagValue, AffixEntryGroup <TEntry> .Builder>();
                                affixesByIndexedByKeyBuilders.Add(indexedKey, keyedAffixes);
                            }

                            if (!keyedAffixes.TryGetValue(group.AFlag, out var groupBuilder))
                            {
                                groupBuilder = new AffixEntryGroup <TEntry> .Builder
                                {
                                    AFlag   = group.AFlag,
                                    Options = group.Options,
                                    Entries = new List <TEntry>()
                                };
                                keyedAffixes.Add(group.AFlag, groupBuilder);
                            }

                            groupBuilder.Entries.Add(entry);
                        }
                    }

                    if (entriesWithNoKey.Count > 0)
                    {
                        affixesWithEmptyKeys.Add(new AffixEntryGroup <TEntry>(group.AFlag, group.Options, AffixEntryCollection <TEntry> .Create(entriesWithNoKey)));
                    }
                    if (entriesWithDots.Count > 0)
                    {
                        affixesWithDots.Add(new AffixEntryGroup <TEntry>(group.AFlag, group.Options, AffixEntryCollection <TEntry> .Create(entriesWithDots)));
                    }
                }
            }

            var affixesByIndexedByKey = new Dictionary <char, AffixEntryGroupCollection <TEntry> >(affixesByIndexedByKeyBuilders.Count);

            foreach (var keyedBuilder in affixesByIndexedByKeyBuilders)
            {
                var indexedAffixGroup = new AffixEntryGroup <TEntry> [keyedBuilder.Value.Count];
                var writeIndex        = 0;
                foreach (var builderPair in keyedBuilder.Value)
                {
                    indexedAffixGroup[writeIndex++] = builderPair.Value.ToGroup();
                }

                affixesByIndexedByKey.Add(keyedBuilder.Key, AffixEntryGroupCollection <TEntry> .TakeArray(indexedAffixGroup));
            }

            return(constructor
                   (
                       affixesByFlag,
                       affixesByIndexedByKey,
                       AffixEntryGroupCollection <TEntry> .Create(affixesWithDots),
                       AffixEntryGroupCollection <TEntry> .Create(affixesWithEmptyKeys),
                       FlagSet.Create(contClasses)
                   ));
        }