public static void Run()
        {
            int[] a = { 1, 3, 5, 7, 9, 10, 11, 13 };
            int[] b = { 5, 7, 13 };

            SequentialList list = new SequentialList(a);

            WriteLine($"{b.Print()} is subset of {a.Print()} = {list.IsSubset(b)}");

            WriteLine(new string('═', 100));

            int[] c = { 1, 3, 5, 7 };
            int[] d = { 1, 4 };

            list = new SequentialList(c);

            WriteLine($"{d.Print()} is subset of {c.Print()} = {list.IsSubset(d)}");

            WriteLine(new string('═', 100));

            string[] str1 = { "one", "three", "five", "seven" };
            string[] str2 = { "one", "four" };

            SequentialList <string> glist = new SequentialList <string>(str1);

            WriteLine($"{str2.Print()} is subset of {str1.Print()} = {glist.IsSubset(str2)}");

            WriteLine(new string('═', 100));
        }
Esempio n. 2
0
        public void TestSequentialList()
        {
            ILinearList <string> list = new SequentialList <string>(5);

            TestLinearList(list);
        }
Esempio n. 3
0
 public void TestSequentialList()
 {
     ILinearList<string> list = new SequentialList<string>(5);
     TestLinearList(list);
 }
        private static string constructUpLevelSequentialListText(int previousLevel, SequentialList sequentialList, Dictionary<int, bool> listTypeHash)
        {
            string listText = "";

            for (int level = previousLevel; level < sequentialList.level - 1; level += 1)
            {
                if (listTypeHash[level] == KARAS.ListTypeUl)
                {
                    listText += "\n<ul>\n<li>";
                }
                else
                {
                    listText += "\n<ol>\n<li>";
                }
            }

            if (sequentialList.level != 1)
            {
                listText += "\n";
            }

            if (sequentialList.type == KARAS.ListTypeUl)
            {
                listText += "<ul>\n<li";
            }
            else
            {
                listText += "<ol>\n<li";
            }

            for (int i = 0; i < sequentialList.items.Count - 1; i += 1)
            {
                listText += KARAS.constructListItemText(sequentialList.items[i]) + "</li>\n<li";
            }

            listText +=
                KARAS.constructListItemText(sequentialList.items[sequentialList.items.Count - 1]);

            return listText;
        }
        private static int constructSequentialLists(string text, int indexOfListStart, List<SequentialList> sequentialLists)
        {
            //match group index.
            const int mgiAllText = 0;
            const int mgiMarks = 1;
            const int mgiMarkedupText = 2;
            const int mgiNextMarks = 3;
            const int mgiBreaks = 4;

            Match match = null;
            int nextMatchIndex = indexOfListStart;
            int levelDiff = 0;
            int previousLevel = 0;

            while (true)
            {
                match = KARAS.RegexList.Match(text, nextMatchIndex);

                if (match.Success == false)
                {
                    break;
                }

                //Update
                levelDiff = match.Groups[mgiMarks].Length - previousLevel;
                previousLevel = match.Groups[mgiMarks].Length;

                //If start of the items. || If Level up or down.
                if (levelDiff != 0)
                {
                    SequentialList sequentialList = new SequentialList();

                    if (match.Groups[mgiMarks].Value[match.Groups[mgiMarks].Length - 1] == '-')
                    {
                        sequentialList.type = KARAS.ListTypeUl;
                    }
                    //If  == '+'
                    else
                    {
                        sequentialList.type = KARAS.ListTypeOl;
                    }

                    sequentialList.level = match.Groups[mgiMarks].Length;
                    sequentialList.items.Add(match.Groups[mgiMarkedupText].Value);
                    sequentialLists.Add(sequentialList);
                }
                //If same Level.
                else
                {
                    SequentialList previousSequentialList
                        = sequentialLists[sequentialLists.Count - 1];
                    bool listType = KARAS.ListTypeUl;

                    if (match.Groups[mgiMarks].Value[match.Groups[mgiMarks].Length - 1] == '-')
                    {
                        listType = KARAS.ListTypeUl;
                    }
                    //If == '+'
                    else
                    {
                        listType = KARAS.ListTypeOl;
                    }

                    if (listType != previousSequentialList.type)
                    {
                        SequentialList sequentialList = new SequentialList();
                        sequentialList.type = listType;
                        sequentialList.level = match.Groups[mgiMarks].Length;
                        sequentialList.items.Add(match.Groups[mgiMarkedupText].Value);
                        sequentialLists.Add(sequentialList);
                    }
                    //If same items type.
                    else
                    {
                        previousSequentialList.items.Add(match.Groups[mgiMarkedupText].Value);
                    }
                }

                if (match.Groups[mgiNextMarks].Length == 0)
                {
                    return match.Groups[mgiAllText].Index
                           + match.Groups[mgiAllText].Length
                           - match.Groups[mgiBreaks].Length;
                }

                nextMatchIndex = match.Groups[mgiNextMarks].Index;
            }

            return -1;
        }
        private static string constructSameLevelSequentialListText(int previousLevel, SequentialList sequentialList, Dictionary<int, bool> listTypeHash)
        {
            //Close previous list item.
            string listText = "";

            if (listTypeHash[previousLevel] == KARAS.ListTypeUl)
            {
                listText += "</li>\n</ul>\n";
            }
            else
            {
                listText += "</li>\n</ol>\n";
            }

            if (sequentialList.type == KARAS.ListTypeUl)
            {
                listText += "<ul>\n";
            }
            else
            {
                listText += "<ol>\n";
            }

            for (int i = 0; i < sequentialList.items.Count - 1; i += 1)
            {
                listText +=
                    "<li" + KARAS.constructListItemText(sequentialList.items[i]) + "</li>\n";
            }

            listText += "<li" +
                KARAS.constructListItemText(sequentialList.items[sequentialList.items.Count - 1]);

            //Note, it is important to update hash.
            listTypeHash[sequentialList.level] = sequentialList.type;

            return listText;
        }
        private static string constructDownLevelSequentialListText(int previousLevel, SequentialList sequentialList, Dictionary<int, bool> listTypeHash)
        {
            //Close previous list item.
            string listText = "</li>\n";

            //Close previous level lists.
            for (int level = previousLevel; level > sequentialList.level; level -= 1)
            {
                if (listTypeHash[level] == KARAS.ListTypeUl)
                {
                    listText += "</ul>\n";
                }
                else
                {
                    listText += "</ol>\n";
                }

                listText += "</li>\n";
            }

            //if current level's list type is different from previous same level's list type.
            if (listTypeHash[sequentialList.level] != sequentialList.type)
            {
                //Note, it is important to update hash.
                if (listTypeHash[sequentialList.level] == KARAS.ListTypeUl)
                {
                    listText += "</ul>\n<ol>\n";
                    listTypeHash[sequentialList.level] = KARAS.ListTypeOl;
                }
                else
                {
                    listText += "</ol>\n<ul>\n";
                    listTypeHash[sequentialList.level] = KARAS.ListTypeUl;
                }
            }

            for (int i = 0; i < sequentialList.items.Count - 1; i += 1)
            {
                listText +=
                    "<li" + KARAS.constructListItemText(sequentialList.items[i]) + "</li>\n";
            }

            listText += "<li" + KARAS.constructListItemText
                (sequentialList.items[sequentialList.items.Count - 1]);

            return listText;
        }