예제 #1
0
        public void GetAreasUsed(BigList <long> usedAreas)
        {
            usedAreas.Add(headerAreaId);

            for (int i = 0; i < BlockCount; ++i)
            {
                usedAreas.Add(blockElements[i]);
            }
        }
예제 #2
0
        internal void GetAreasUsed(BigList <long> list)
        {
            list.Add(startArea.Id);
            list.Add(indexHeaderPointer);

            foreach (var block in indexBlocks)
            {
                list.Add(block.StartOffset);
                long[] blockPointers = block.GetBlockPointers();
                list.AddRange(blockPointers);
            }
        }
예제 #3
0
        public static void InsertSort()
        {
            var index = new SortedCollection <SqlObject, long>();
            var items = new BigList <SqlObject>();

            items.Add(SqlObject.Integer(435));
            items.Add(SqlObject.Integer(1920));

            var comparer = new CollectionComparer(items);

            index.InsertSort(SqlObject.Double(2234.99), 45, comparer);

            Assert.Equal(1, index.Count);
        }
예제 #4
0
        static void Main(string[] args)
        {
            var asd = new BigList <int>();

            asd.Add(0);
            asd.Add(1);
            asd.Add(2);
            asd.Add(3);

            asd.Insert(50, 10);
            foreach (var item in asd)
            {
                Console.WriteLine(item);
            }
        }
예제 #5
0
파일: GSS.cs 프로젝트: sebgod/hime
 /// <summary>
 /// Opens a new generation in this GSS
 /// </summary>
 /// <returns>The index of the new generation</returns>
 public int CreateGeneration()
 {
     nodeGenerations.Add(new GSSGeneration(nodeLabels.Size));
     edgeGenerations.Add(new GSSGeneration(edges.Size));
     generation++;
     return(generation);
 }
예제 #6
0
        static void Main(string[] args)
        {
            string nextLine;

            string[] splitText;
            var      numbers = new BigList <int>();

            while ((nextLine = Console.ReadLine()) != "EXIT")
            {
                splitText = nextLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                switch (splitText[0])
                {
                case "ADD":
                    var num = int.Parse(splitText[1]);
                    numbers.Add(num);
                    break;

                case "FIND":
                    FindCommand(numbers);
                    break;
                }
            }
            Console.Write(sb.ToString());
        }
예제 #7
0
        public TableIndex Subset(ITable table, int[] columns)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }
            if (columns.Length > 1)
            {
                throw new NotSupportedException("multi-columns subset not implemented yet");
            }

            // Resolve table rows in this table scheme domain.
            var rowSet = new BigList <long>(table.RowCount);

            foreach (var row in table)
            {
                rowSet.Add(row.Number);
            }

            var rows = table.ResolveRows(columns[0], rowSet, Table);

            // Generates an IIndex which contains indices into 'rowSet' in
            // sorted order.
            var newSet = OrderRows(rows).ToBigArray();

            // Our 'new_set' should be the same size as 'rowSet'
            if (newSet.Length != rowSet.Count)
            {
                throw new Exception("Internal sort error in finding sub-set.");
            }

            return(CreateSubset(table, columns[0], newSet));
        }
예제 #8
0
        private IEnumerable <long> GetMaxFromEachGroup(int colNum)
        {
            var refTab = table;

            var extractRows = new BigList <long>();
            var size        = groupLinks.Count;

            for (int i = 0; i < size; ++i)
            {
                var       group         = groupLinks[i];
                SqlObject max           = null;
                long      toTakeInGroup = -1;

                for (int j = 0; j < group.Count; j++)
                {
                    var groupRow = group[j];
                    var value    = refTab.GetValue(groupRow, colNum);

                    if (max == null || value.CompareTo(max) > 0)
                    {
                        max           = value;
                        toTakeInGroup = groupRow;
                    }
                }

                extractRows.Add(toTakeInGroup);
            }

            return(extractRows);
        }
예제 #9
0
        public static void Editor()
        {
            var text = new BigList<string> ();
            string command = " ";
            do {
                command = Console.ReadLine();
                var parts = command.Split(' ');

                switch( parts[0]) {
                case "INSERT":
                    text.Add(parts[1]);
                    Console.WriteLine("OK");
                    break;

                case "APPEND":
                    text.AddToFront(parts[1]);
                    Console.WriteLine("OK");

                    break;

                case "DELETE":
                    try {
                        text.RemoveRange(int.Parse(parts[1]), int.Parse(parts[2]));
                        Console.WriteLine("OK");
                    }
                    catch(Exception) {
                        Console.WriteLine("ERROR");
                    }
                    break;
                }

            } while("PRINT" != command);
            Console.WriteLine (text);
        }
예제 #10
0
 private static void Add(char[] stringToAdd, BigList <char> stringContainer)
 {
     foreach (var character in stringToAdd)
     {
         stringContainer.Add(character);
     }
 }
예제 #11
0
        private static void HandleAddCommand(string[] command)
        {
            string name     = command[1];
            string type     = command[2];
            int    age      = int.Parse(command[3]);
            int    position = int.Parse(command[4]) - 1;

            Player player = new Player(name, type, age, position);

            bool typeIsFound = playersSortedByType.ContainsKey(type);

            if (!typeIsFound)
            {
                playersSortedByType.Add(type, new SortedSet <Player>());
            }

            if (playersSortedByType[type].Contains(player))
            {
                return;
            }

            playersSortedByType[type].Add(player);

            if (position > players.Count)
            {
                players.Add(player);
            }
            else
            {
                players.Insert(position, player);
            }

            Console.WriteLine("Added player {0} to position {1}", player.Name, player.Position + 1);
        }
예제 #12
0
        public virtual VirtualTable GroupMax(ObjectName maxColumn)
        {
            BigList <long> rowList;

            if (table.RowCount <= 0)
            {
                rowList = new BigList <long>(0);
            }
            else
            {
                // OPTIMIZATION: This should be optimized.  It should be fairly trivial
                //   to generate a Table implementation that efficiently merges this
                //   function table with the reference table.

                // This means there is no grouping, so merge with entire table,
                var rowCount = table.RowCount;
                rowList = new BigList <long>(rowCount);
                using (var en = table.GetEnumerator()) {
                    while (en.MoveNext())
                    {
                        rowList.Add(en.Current.Number);
                    }
                }
            }

            // Create a virtual table that's the new group table merged with the
            // functions in this...

            var tabs    = new[] { table, this };
            var rowSets = new IEnumerable <long>[] { rowList, rowList };

            return(new VirtualTable(tabs, rowSets));
        }
예제 #13
0
        static void Main(string[] args)
        {
            var           sequence    = Enumerable.Range(1, 12);
            BigList <int> numbersList = new BigList <int>(sequence);
            BigList <int> temp        = new BigList <int>();

            int[] swapNumbers = new int[] { 11, 5, 10, 6, 9, 10 };
            int   i           = 0; //TODO - REMOVE
            int   swap        = swapNumbers[i];

            //int swap = 15;
            Console.WriteLine($"Swap number = {swap}");
            var found = numbersList.IndexOf(swap);

            Console.WriteLine("Original sequence:");
            Console.WriteLine(string.Join(" ", numbersList));

            //cut items before and after swap number

            for (int j = 0; j < numbersList.IndexOf(swap); j++)
            {
                temp.Add(numbersList[j]);
            }

            while (numbersList[0] != swap + 1)
            {
                numbersList.RemoveAt(0);
            }

            Console.WriteLine("Numbers before and after swap number:");
            Console.WriteLine(string.Join(" ", temp));
            Console.WriteLine(string.Join(" ", numbersList));

            //add numbers after swap

            numbersList.Add(swap);
            foreach (var number in temp)
            {
                numbersList.Add(number);
            }
            temp.RemoveRange(0, temp.Count);
            Console.WriteLine("New sequence:");
            Console.WriteLine(string.Join(" ", numbersList));
            //Console.WriteLine($"Number of items in temporary list: {temp.Count}");

            Console.WriteLine("END OF ROUND\n\n");
        }
예제 #14
0
    static string Append(string name)
    {
        names.Add(name);

        data.Add(name);

        return("OK");
    }
예제 #15
0
파일: GSS.cs 프로젝트: sebgod/hime
        /// <summary>
        /// Creates a new edge in the GSS
        /// </summary>
        /// <param name="from">The edge's starting node</param>
        /// <param name="to">The edge's target node</param>
        /// <param name="label">The edge's label</param>
        public void CreateEdge(int from, int to, int label)
        {
            edges.Add(new GSSEdge(from, to, label));
            GSSGeneration data = edgeGenerations[generation];

            data.Count++;
            edgeGenerations[generation] = data;
        }
예제 #16
0
        private static void Insert(string[] command)
        {
            int    position = int.Parse(command[1]);
            string name     = command[2];

            if (position == 0)
            {
                list.AddToFront(name);
                if (!bla.ContainsKey(name))
                {
                    bla.Add(name, 0);
                }

                bla[name]++;

                sb.AppendLine("OK");
            }
            else if (position == list.Count)
            {
                list.Add(name);
                if (!bla.ContainsKey(name))
                {
                    bla.Add(name, 0);
                }

                bla[name]++;

                sb.AppendLine("OK");
            }
            else if (position > list.Count)
            {
                sb.AppendLine("Error");
            }
            else
            {
                list.Insert(position, name);

                sb.AppendLine("OK");
                if (!bla.ContainsKey(name))
                {
                    bla.Add(name, 0);
                }

                bla[name]++;
            }
        }
예제 #17
0
        private static void Append(BigList<char> text, string textToAppend, bool shouldPrint = true)
        {
            for (int i = 0; i < textToAppend.Length; i++)
            {
                text.Add(textToAppend[i]);
            }

            PrintSuccessMessage(shouldPrint);
        }
예제 #18
0
        public static void ContainsItem()
        {
            var index = new SortedCollection <SqlObject, long>();
            var items = new BigList <SqlObject>();

            items.Add(SqlObject.Integer(435));
            items.Add(SqlObject.Integer(1920));
            items.Add(SqlObject.Integer(9182));

            var comparer = new CollectionComparer(items);

            index.InsertSort(items[0], 0, comparer);
            index.InsertSort(items[1], 1, comparer);
            index.InsertSort(items[2], 2, comparer);

            Assert.True(index.Contains(SqlObject.Integer(435), comparer));
            Assert.False(index.Contains(SqlObject.Integer(21), comparer));
        }
예제 #19
0
파일: GSS.cs 프로젝트: sebgod/hime
        /// <summary>
        /// Creates a new node in the GSS
        /// </summary>
        /// <param name="state">The GLR state represented by the node</param>
        /// <returns>The node's identifier</returns>
        public int CreateNode(int state)
        {
            int           node = nodeLabels.Add(state);
            GSSGeneration data = nodeGenerations[generation];

            data.Count++;
            nodeGenerations[generation] = data;
            return(node);
        }
예제 #20
0
        public static Pair <Genotype, Genotype> Splice(Genotype genome1, Genotype genome2, int splicePoint1, int splicePoint2)
        {
            // TODO Here we use an inefficient version which creates two containers of genes
            // to replace the originals.  Ideally, this would be done as it was in the
            // C++ version with std::list splicing - or by implementing this class in C++/CLR

            Debug.Assert(genome1.Count >= 2);
            Debug.Assert(genome2.Count >= 2);
            Debug.Assert(splicePoint1 < genome1.Count);
            Debug.Assert(splicePoint2 < genome2.Count);

            BigList <Gene>     newGenes1 = new BigList <Gene>();
            BigList <Gene>     newGenes2 = new BigList <Gene>();
            IEnumerator <Gene> p         = genome1.genes.GetEnumerator();

            for (int i = 0; i < splicePoint1; ++i)
            {
                p.MoveNext();
                newGenes1.Add((Gene)p.Current.Clone());
            }

            IEnumerator <Gene> q = genome2.genes.GetEnumerator();

            for (int j = 0; j < splicePoint2; ++j)
            {
                q.MoveNext();
                newGenes2.Add((Gene)q.Current.Clone());
            }

            for (int i = splicePoint1; i < genome1.genes.Count; ++i)
            {
                p.MoveNext();
                newGenes2.Add((Gene)p.Current.Clone());
            }

            for (int j = splicePoint2; j < genome2.genes.Count; ++j)
            {
                q.MoveNext();
                newGenes1.Add((Gene)q.Current.Clone());
            }

            Debug.Assert(newGenes1.Count + newGenes2.Count == genome1.Count + genome2.Count);
            return(new Pair <Genotype, Genotype>(new Genotype(newGenes1), new Genotype(newGenes2)));
        }
예제 #21
0
        private static string Append(IList <string> commandArgs)
        {
            var personName = commandArgs[0];

            supermarketQueue.Add(personName);

            UpdatePersonCount(personName);

            return("OK");
        }
예제 #22
0
        public static void CreateFromOtherIndex()
        {
            var index = new SortedCollection <SqlObject, long>();
            var items = new BigList <SqlObject>();

            items.Add(SqlObject.Integer(435));
            items.Add(SqlObject.Integer(1920));
            items.Add(SqlObject.Integer(9182));

            var comparer = new CollectionComparer(items);

            index.InsertSort(items[0], 0, comparer);
            index.InsertSort(items[1], 1, comparer);
            index.InsertSort(items[2], 2, comparer);

            var index2 = new SortedCollection <SqlObject, long>(index);

            Assert.Equal(index.Count, index2.Count);
        }
예제 #23
0
        static void Main(string[] args)
        {
            BigList <string> totalJedi = new BigList <string>();
            Queue <string>   knights   = new Queue <string>();
            List <string>    padawans  = new List <string>();
            int n = int.Parse(Console.ReadLine());

            string[] jedis = Console.ReadLine().Split();

            for (int i = 0; i < n; i++)
            {
                string temp = jedis[i];
                switch (temp[0])
                {
                case 'M':
                    totalJedi.Add(jedis[i]);
                    break;

                case 'K':
                    knights.Enqueue(jedis[i]);
                    break;

                case 'P':
                    padawans.Add(jedis[i]);
                    break;

                default:
                    break;
                }
            }
            while (knights.Count != 0)
            {
                totalJedi.Add(knights.Dequeue());
            }

            foreach (var padawan in padawans)
            {
                totalJedi.Add(padawan);
            }

            Console.WriteLine(string.Join(" ", totalJedi));
        }
예제 #24
0
 private static void AppendPerson(string name)
 {
     queueOfPositions.Add(name);
     if (!queueOfNames.ContainsKey(name))
     {
         queueOfNames.Add(name, 0);
     }
     queueOfNames[name]++;
     uniqueClientId++;
     result.AppendLine("OK");
 }
예제 #25
0
        private BigList <long> CalculateTableRows()
        {
            var size    = RowCount;
            var allList = new BigList <long>(size);

            for (int i = 0; i < size; ++i)
            {
                allList.Add(i);
            }
            return(allList);
        }
예제 #26
0
        private static void AppendCommand(Command command, StringBuilder output)
        {
            name.Add(command.Param);
            if (!findNames.ContainsKey(command.Param))
            {
                findNames.Add(command.Param, 0);
            }
            findNames[command.Param]++;

            output.AppendLine("OK");
        }
예제 #27
0
        protected override RawTableInfo GetRawTableInfo(RawTableInfo rootInfo)
        {
            var size    = RowCount;
            var allList = new BigList <long>(size);

            for (long i = 0; i < size; ++i)
            {
                allList.Add(i);
            }

            return(GetRawTableInfo(rootInfo, allList));
        }
예제 #28
0
 static void AddPlayer(Player p, BigList<Player> ranking)
 {
     if (ranking.Count >= p.Position)
     {
         ranking.Insert(p.Position - 1, p);
     }
     else
     {
         ranking.Add(p);
     }
     Console.WriteLine("Added player {0} to position {1}", p.Name, p.Position);
 }
예제 #29
0
        public static void SearcLast_Sort()
        {
            var index = new SortedCollection <SqlObject, long>();
            var items = new BigList <SqlObject>();

            items.Add(SqlObject.Integer(435));
            items.Add(SqlObject.Integer(1920));
            items.Add(SqlObject.Integer(9182));

            var comparer = new CollectionComparer(items);

            index.InsertSort(items[0], 0, comparer);
            index.InsertSort(items[1], 1, comparer);
            index.InsertSort(items[2], 2, comparer);

            Assert.Equal(3, index.Count);

            var first = index.SearchLast(SqlObject.Integer(435), comparer);

            Assert.Equal(0, first);
        }
예제 #30
0
        private void DoInsertSort(BigList <long> list, long row)
        {
            var listSize = list.Count;

            if (listSize == 0)
            {
                list.Add(row);
            }
            else
            {
                var point = HighestSearch(GetKey(row), list, 0, listSize - 1);
                if (point == listSize)
                {
                    list.Add(row);
                }
                else
                {
                    list.Insert(point, row);
                }
            }
        }
예제 #31
0
        public static void AddAndRemoveItem()
        {
            var index = new SortedCollection <SqlObject, long>();
            var items = new BigList <SqlObject>();

            items.Add(SqlObject.Integer(435));
            items.Add(SqlObject.Integer(1920));
            items.Add(SqlObject.Integer(9182));

            var comparer = new CollectionComparer(items);

            index.InsertSort(items[0], 0, comparer);
            index.InsertSort(items[1], 1, comparer);
            index.InsertSort(items[2], 2, comparer);

            Assert.Equal(3, index.Count);

            var value = index.RemoveSort(SqlObject.Integer(435), 0, comparer);

            Assert.Equal(0, value);
        }
예제 #32
0
        private IEnumerable <long> GetTopRowsFromEachGroup()
        {
            var extractRows = new BigList <long>();
            var size        = groupLinks.Count;

            for (int i = 0; i < size; ++i)
            {
                var r = groupLinks[i];
                extractRows.Add(r[0]);
            }

            return(extractRows);
        }
 public JsonResult Insert()
 {
     OrderedDictionary<int, BigList<double>> orderedDic = new OrderedDictionary<int, BigList<double>>();
     BigList<double> bigList = new BigList<double>();
     Parallel.For(1, 10000, x =>
     {
        lock(this)
         {
             bigList.Add(x * Math.PI * new Random().NextDouble());
         }
     });
     orderedDic.Add(Environment.CurrentManagedThreadId, bigList);
     tree.Insert(orderedDic, DuplicatePolicy.InsertFirst, out orderedDic);
     return Json(new { OrderedDictionary = orderedDic }, JsonRequestBehavior.AllowGet);
 }
예제 #34
0
        public GameScreen()
        {
            closedList = new BigList<GameObject>();
            shells = new BigList<Shell>();

            player = new Player();
            earth = new Earth();
            glow = new Glow();
            //map = new Map();

            mCollisions = new MasterCollisions();

            closedList.Add(glow);
            closedList.Add(player);
            closedList.Add(earth);

            for (int i = 0; i < 100; i++)
            {
                shells.Add(new Shell());

                closedList.Add(shells.Last());

            }
        }
예제 #35
0
        /// <summary>
        /// BigList<T> (WITH DUPLICATES)
        /// Editable sequence of indexed items
        /// Like List<T> but provides
        /// Fast Insert / Delete operations (at any position)
        /// Fast Copy / Concat / Sub-range operations
        /// Implemented by the data structure "Rope"
        /// Special kind of balanced binary tree: http://en.wikipedia.org/wiki/Rope_(data_structure)
        /// </summary>
        private static void TestBigList()
        {
            BigList<Student> students = new BigList<Student>();
            var student1 = new Student("First DUPLICATE", 21);
            var student2 = new Student("Second", 21);
            var student3 = new Student("Third", 22);
            var student4 = new Student("Forth", 23);
            var student5 = new Student("Fifth", 24);
            Console.WriteLine();
            students.Add(student1);
            students.Add(student2);
            students.Add(student3);
            students.Add(student4);
            students.Add(student5);
            students.Add(student1);
            Console.WriteLine("===== BEFORE SORT =====");
            Console.WriteLine("Index of student1: " + students.BinarySearch(student1));
            Console.WriteLine("Index of student2: " + students.BinarySearch(student2));
            Console.WriteLine("Index of student3: " + students.BinarySearch(student3));
            Console.WriteLine("Index of student4: " + students.BinarySearch(student4));
            Console.WriteLine("Index of student5: " + students.BinarySearch(student5));
            foreach (var item in students)
            {
                Console.WriteLine(item);
            }

            students.Sort();
            Console.WriteLine("===== AFTER SORT =====");
            Console.WriteLine("Index of student1: " + students.BinarySearch(student1));
            Console.WriteLine("Index of student2: " + students.BinarySearch(student2));
            Console.WriteLine("Index of student3: " + students.BinarySearch(student3));
            Console.WriteLine("Index of student4: " + students.BinarySearch(student4));
            Console.WriteLine("Index of student5: " + students.BinarySearch(student5));
            foreach (var item in students)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("===== INDEX students[3] =====");
            Console.WriteLine(students[3]);
        }
        public static void FillLabourNormList(TrudoyomkostDBContext dbcontext, ref BigList<LabourNorm> inputList)
        {
            var tempresult = from labourlist in dbcontext.LabourNorm
                             select labourlist;
            inputList.Clear();
            //IList temp =  tempresult.ToList();

            foreach (var item in tempresult)
            {
                inputList.Add(item);
            }
        }
        public static void FillWhereOperationUseList(TrudoyomkostDBContext dbcontext, ref BigList<WhereOperationUse> inputList)
        {
            var tempresult = from labourlist in dbcontext.WhereOperationUse
                             select labourlist;
            inputList.Clear();

            foreach (var item in tempresult)
            {
                inputList.Add(item);
            }
        }
    static void Main()
    {
        Console.Write("Bag of Integers: ");
        var bagOfInts = new Bag<int>();
        bagOfInts.Add(3);
        bagOfInts.Add(5);
        bagOfInts.Add(5);
        bagOfInts.Add(5);
        bagOfInts.Add(10);
        bagOfInts.Add(20);
        bagOfInts.Add(20);
        bagOfInts.Remove(5);
        bagOfInts.RemoveAllCopies(20);
        bagOfInts.UnionWith(new Bag<int>() { 3, 3, 4, 4, 5, 5 });
        Console.WriteLine(bagOfInts);

        Console.Write("OrderedBag of Integers: ");
        var orderedBagOfInts = new OrderedBag<int>();
        orderedBagOfInts.Add(3);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(10);
        orderedBagOfInts.Add(20);
        orderedBagOfInts.Add(20);
        orderedBagOfInts.Remove(5);
        orderedBagOfInts.RemoveAllCopies(20);
        orderedBagOfInts.UnionWith(new OrderedBag<int>() { 3, 3, 4, 4, 5, 5 });
        Console.WriteLine(orderedBagOfInts);
        Console.WriteLine("Sub-range [5...10]: " +
            orderedBagOfInts.Range(5, true, 10, true));
        
        Console.Write("Set of Integers: ");
        var setOfInts = new Set<int>();
        setOfInts.Add(3);
        setOfInts.Add(5);
        setOfInts.Add(5);
        setOfInts.Add(5);
        setOfInts.Add(10);
        setOfInts.Add(20);
        setOfInts.Add(20);
        setOfInts.Remove(5);
        setOfInts.UnionWith(new Set<int>() { 3, 4, 5 });
        Console.WriteLine(setOfInts);

        Console.Write("OrderedSet of Integers: ");
        var orderedSetOfInts = new OrderedSet<int>();
        orderedSetOfInts.Add(3);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(10);
        orderedSetOfInts.Add(20);
        orderedSetOfInts.Add(20);
        orderedSetOfInts.Remove(5);
        orderedSetOfInts.UnionWith(new OrderedSet<int>() { 3, 4, 5 });
        Console.WriteLine(orderedSetOfInts);
        Console.WriteLine("Sub-range [5...20): " +
            orderedSetOfInts.Range(5, true, 20, false));

        Console.Write("MultiDictionary<string,int>: ");
        var studentGrades = new MultiDictionary<string, int>(true);
        studentGrades.Add("Peter", 3);
        studentGrades.Add("Peter", 4);
        studentGrades.Add("Peter", 4);
        studentGrades.Add("Stanka", 6);
        studentGrades.Add("Stanka", 5);
        studentGrades.Add("Stanka", 6);
        studentGrades.Add("Tanya", 6);
        studentGrades.Add("Tanya", 4);
        Console.WriteLine(studentGrades);

        Console.WriteLine("OrderedMultiDictionary<string,int>:");
        var distancesFromSofia = new OrderedMultiDictionary<int, string>(true);
        distancesFromSofia.Add(149, "Plovdiv");
        distancesFromSofia.Add(505, "Varna");
        distancesFromSofia.Add(394, "Bourgas");
        distancesFromSofia.Add(310, "Rousse");
        distancesFromSofia.Add(163, "Pleven");
        distancesFromSofia.Add(163, "Troyan");
        foreach (var distanceTowns in distancesFromSofia)
        {
            Console.WriteLine("\t" + distanceTowns);
        }

        Console.Write("Deque<string>: ");
        var people = new Deque<string>();
        people.AddToBack("Kiro");
        people.AddToBack("Maria");
        people.AddToFront("Steve");
        people.AddManyToBack(new string[] { "Ivan", "Veronika" });
        Console.WriteLine(people);

        Console.Write("BigList<int>: ");
        var ints = new BigList<int>();
        // var ints = new List<int>();
        for (int i = 0; i < 1000000; i++)
        {
            ints.Add(i);
        }
        for (int i = 0; i < 50000; i++)
        {
            ints.Insert(i, i);
        }
        Console.WriteLine(ints.Count);
    }
        public static void Main()
        {
            BigList<string> names = new BigList<string>();
            Dictionary<string,int> namesCounter= new Dictionary<string, int>();

            string[] input = Console.ReadLine().Split(' ');

            StringBuilder result = new StringBuilder();

            while (input[0] != "End")
            {
                switch (input[0])
                {
                    case "Append":
                        {
                            names.Add(input[1]);
                            if (!namesCounter.ContainsKey(input[1]))
                            {
                                namesCounter.Add(input[1], 1);
                            }
                            else
                            {
                                namesCounter[input[1]]++;
                            }

                            result.AppendLine("OK");
                            break;
                        }
                    case "Insert":
                        {
                            var position = int.Parse(input[1]);

                            try
                            {
                                names.Insert(position, input[2]);
                                result.AppendLine("OK");
                            }
                            catch (ArgumentOutOfRangeException ex)
                            {
                                result.AppendLine("Error");
                                break;
                            }

                            if (!namesCounter.ContainsKey(input[2]))
                            {
                                namesCounter.Add(input[2], 1);
                            }
                            else
                            {
                                namesCounter[input[2]]++;
                            }

                            break;

                        }

                    case "Find":
                        {
                            string name = input[1];

                            if (namesCounter.ContainsKey(input[1]))
                            {
                                result.AppendLine(namesCounter[input[1]].ToString());
                            }
                            else
                            {
                                result.AppendLine("0");
                            }
                            break;
                        }

                    case "Serve":
                        {
                            int count = int.Parse(input[1]);

                            if (count > names.Count)
                            {
                                result.AppendLine("Error");
                                break;
                            }

                           var l = names.Range(0, count);
                            StringBuilder k = new StringBuilder();

                            for(var p=0;p<l.Count;p++)
                            {
                                var o = l[p];
                                k.Append(o).Append(' ');
                                namesCounter[o]--;
                            }

                            result.AppendLine(k.ToString().Trim(' '));

                            names.RemoveRange(0,count);

                            break;;
                        }
                }

                input = Console.ReadLine().Split(' ');
            }

            Console.WriteLine(result);
        }
    static void Main()
    {
        var rope = new BigList<char>();
        string input = "";

        while (input != "END")
        {
            input = Console.ReadLine();
            var inputTokens = input.Trim().Split(' ');
            var command = inputTokens[0];

            if (command == "APPEND")
            {
                var textToAppend = input.Substring(7);
                for (int i = 0; i < textToAppend.Length; i++)
                {
                    rope.Add(textToAppend[i]);
                }
                Console.WriteLine("OK");
            }

            if (command == "INSERT")
            {
                int positionToInsert = int.Parse(inputTokens[1]);
                if (IsValidIndex(positionToInsert, rope))
                {
                    var textToInsert = inputTokens[2];
                    rope.InsertRange(positionToInsert, textToInsert);
                    Console.WriteLine("OK");
                }
                else
                {
                    Console.WriteLine("ERROR");
                }
            }

            if (command == "DELETE")
            {
                int deleteFrom = int.Parse(inputTokens[1]);
                int deleteCount = int.Parse(inputTokens[2]);
                if ((IsValidIndex(deleteFrom, rope) && IsValidIndex(deleteCount, rope)) && ((deleteFrom + deleteCount) <= rope.Count))
                {
                    rope.RemoveRange(deleteFrom, deleteCount);
                    Console.WriteLine("OK");
                }
                else
                {
                    Console.WriteLine("ERROR");
                }

            }

            if (command == "REPLACE")
            {
                int replaceFrom = int.Parse(inputTokens[1]);
                int replaceCount = int.Parse(inputTokens[2]);

                if ((IsValidIndex(replaceFrom, rope) && IsValidIndex(replaceCount, rope)) && ((replaceFrom + replaceCount) <= rope.Count))
                {
                    var replaceText = new List<string>();
                    for (int i = 3; i < inputTokens.Length; i++)
                    {
                        replaceText.Add(inputTokens[i]);
                    }

                    rope.RemoveRange(replaceFrom, replaceCount);
                    rope.InsertRange(replaceFrom, string.Join(" ", replaceText));

                    Console.WriteLine("OK");
                }
                else
                {
                    Console.WriteLine("ERROR");
                }
            }

            if (command == "PRINT")
            {
                Console.WriteLine(string.Join("", rope));
            }
        }
    }
예제 #41
0
        private static void Main(string[] args)
        {
            var queue = new BigList<string>();
            var names = new Dictionary<string, int>();

            var commandParts = Console.ReadLine().Split(' ');
            var result = new StringBuilder();
            while (commandParts[0] != "End")
            {
                switch (commandParts[0])
                {
                    case "Append":
                        queue.Add(commandParts[1]);
                        if (!names.ContainsKey(commandParts[1]))
                        {
                            names[commandParts[1]] = 0;
                        }
                        names[commandParts[1]]++;
                        result.AppendLine("OK");
                        break;
                    case "Insert":
                        var index = int.Parse(commandParts[1]);
                        if (index > queue.Count)
                        {
                            result.AppendLine("Error");
                            break;
                        }
                        result.AppendLine("OK");
                         if (!names.ContainsKey(commandParts[2]))
                        {
                            names[commandParts[2]] = 0;
                        }
                        names[commandParts[2]]++;
                        if (index == queue.Count)
                        {
                            queue.Add(commandParts[2]);
                            break;
                        }
                        queue.Insert(index, commandParts[2]);
                        break;

                    case "Find":
                        if (!names.ContainsKey(commandParts[1]))
                        {
                            result.AppendLine("0"); break;
                        }
                        result.AppendLine(names[commandParts[1]].ToString());
                        break;
                    case "Serve":
                        var count = int.Parse(commandParts[1]);
                        if (count > queue.Count)
                        {
                            result.AppendLine("Error");
                            break;
                        }
                        var served = new StringBuilder();
                        for (int i = 0; i < count; i++)
                        {
                            var person = queue[0];
                            names[person]--;
                            served.AppendFormat(" {0}", person);
                            queue.RemoveAt(0);
                        }
                        result.AppendLine(served.ToString().Trim());
                        break;
                }

                commandParts = Console.ReadLine().Split(' ');
            }

            Console.WriteLine(result.ToString());
        }