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); }
private static void Edit(string line, BigList<char> rope) { string[] tokens = line.Split(' '); string text; int index; int count; bool success = false; switch (tokens[0]) { case "INSERT": string position = tokens[tokens.Length - 1]; text = line.Substring(7, line.Length - 8 - position.Length); success = InsertInRope(rope, text, int.Parse(position)); break; case "APPEND": text = line.Substring(7, line.Length - 7); success = AppendToRope(rope, text); break; case "DELETE": index = int.Parse(tokens[1]); count = int.Parse(tokens[2]); success = DeleteFromRopeAt(rope, index, count); break; case "REPLACE": index = int.Parse(tokens[1]); count = int.Parse(tokens[2]); text = line.Substring(10 + index.ToString().Length + count.ToString().Length, line.Length - 10 - index.ToString().Length - count.ToString().Length); success = ReplaceInRopeAt(rope, text, index, count); break; } Console.WriteLine(success ? "OK" : "ERROR"); }
public GameCollection() { this.usersByUsername = new Dictionary <string, User>(); this.gamesByName = new Dictionary <string, Game>(); this.scoreboard = new Dictionary <string, SortedSet <Score> >(); this.prefixes = new BigList <string>(); }
public void BigList_SetValue_UnitTest() { var bigList = new BigList <Object>(); var object0 = new object(); bigList.SetValue(0, object0); var object0Actual = bigList.GetElement(0); Assert.IsTrue(ReferenceEquals(object0, object0Actual)); var object10 = new object(); bigList.SetValue(10, object10); var object10Actual = bigList.GetElement(10); Assert.IsTrue(ReferenceEquals(object10, object10Actual)); var object250000000 = new object(); bigList.SetValue(250000000, object250000000); var object250000000Actual = bigList.GetElement(250000000); Assert.IsTrue(ReferenceEquals(object250000000, object250000000Actual)); }
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()); }
public void Clear() { this.smallestElements = new SortedDictionary <T, List <T> >(new SmallestElement()); this.biggestElements = new SortedDictionary <T, List <T> >(new BiggestElement()); this.firstAndLastElements = new BigList <T>(); this.totalElements = 0; }
public void FillResources( IPsnProtocolConfiguration protocol, DateTime beginTime, IEnumerable <IPsnProtocolCommandPartConfigurationCycle> cycleCmdPartInfo, IEnumerable <IPsnProtocolCommandPartConfiguration> commandPartsToMap) { var goodCommandParts = protocol.CommandParts.Where(cp => cp.Address != null && cp.CommandCode != null && cp.CrcHigh != null && cp.CrcLow != null).ToArray(); byte[] dataBytes; using (var dataStream = _dataStreamGetter.Invoke()) { dataBytes = new byte[dataStream.Length]; dataStream.Read(dataBytes, 0, (int)dataStream.Length); } if (_pagesIndex == null) { var fr = BuildPagesIndex(dataBytes); _pagesIndex = fr.FullIndex; _timeSortedGoodPages = fr.TimeSortedGoodPages; _goodPagesOnlyGoodBytes = GetOnlyGoodData(fr.TimeSortedGoodPages, dataBytes); _commandsMap = BuildCommandsMap(goodCommandParts, cycleCmdPartInfo, _goodPagesOnlyGoodBytes, beginTime, _timeSortedGoodPages); } _lastPsnProtocolId = protocol.Information.Id; _areResourcesFree = false; }
/// <summary> /// Initializes a new instance of the <see cref="MutexNode"/> class. /// </summary> /// <param name="label">The label.</param> public AggregatorNode(string label) { _label = label; _type = ReteNodeType.Aggregator; _items = new BigList <Token>(); _inferredFacts = new List <WME>(); }
/// <summary> /// Constructor to create an instance of graph. /// </summary> public Graph() { VertexArray = new BigList <Vertex <T> >(); EdgeArray = new BigList <Edge <U> >(); DeletedVertexCount = 0; DeletedEdgeCount = 0; }
static void Main(string[] args) { BigList <Player> playersRanklist = new BigList <Player>(); Dictionary <string, OrderedSet <Player> > playersByType = new Dictionary <string, OrderedSet <Player> >(); StringBuilder resultBuilder = new StringBuilder(); string command; while ((command = Console.ReadLine()) != "end") { string[] commandParams = command.Split(); switch (commandParams[0]) { case "add": AddPlayer(playersRanklist, playersByType, resultBuilder, commandParams); break; case "find": FindType(playersByType, resultBuilder, commandParams); break; case "ranklist": GetRanklist(playersRanklist, resultBuilder, commandParams); break; } } Console.WriteLine(resultBuilder.ToString()); }
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)); }
public BigList GetByInsideDigits() { var linked = new BigList(); if (MaxEdge < MinEdge) { for (var i = MinEdge; i >= MaxEdge; i--) { var s = string.Empty; if (ContainsDigit((uint)i, (uint)DigitPattern)) { s += $"Number {DigitPattern} present in the number {i}"; } linked.AddLast(i, !string.IsNullOrEmpty(s) ? s : i.ToString(CultureInfo.InvariantCulture)); } return(linked); } for (var i = MinEdge; i <= MaxEdge; i++) { var s = string.Empty; if (ContainsDigit((uint)i, (uint)DigitPattern)) { s += $"Number {DigitPattern} present in the number {i}"; } linked.AddLast(i, !string.IsNullOrEmpty(s) ? s : i.ToString(CultureInfo.InvariantCulture)); } return(linked); }
/// <summary> /// Initializes a new instance of the Fallen-8 class. /// </summary> public Fallen8() { IndexFactory = new IndexFactory(); _graphElements = new BigList<AGraphElement>(); ServiceFactory = new ServiceFactory(this); IndexFactory.Indices.Clear(); }
public static void Main() { var rope = new BigList<char>(); var builder = new StringBuilder(); var input = Console.ReadLine().Split(); while (input[0] != "END") { var command = input[0]; switch (command) { case "INSERT": Insert(rope, builder, int.Parse(input[1]), input[2]); break; case "APPEND": Append(rope, builder, input[1]); break; case "DELETE": Delete(rope, builder, int.Parse(input[1]), int.Parse(input[2])); break; case "PRINT": Print(rope, builder); break; case "REPLACE": Replace(rope, builder, int.Parse(input[1]), int.Parse(input[2]), input[3]); break; } input = Console.ReadLine().Split(); } Console.WriteLine(builder.ToString().Trim()); }
private RawTableInfo GetRawTableInfo(RawTableInfo info, BigList <long> rows) { if (this is IRootTable) { info.Add((IRootTable)this, CalculateTableRows()); } else { for (int i = 0; i < Tables.Length; ++i) { // Resolve the rows into the parents indices. var newRowSet = ResolveTableRows(rows, i).ToBigList(); var table = Tables[i]; if (table is IRootTable) { info.Add((IRootTable)table, newRowSet); } else if (table is JoinedTable) { ((JoinedTable)table).GetRawTableInfo(info, newRowSet); } } } return(info); }
public void Prepend(string username, string str) { BigList <char> user_str = users.GetValue(username); cache[username].Push(new BigList <char>(user_str)); user_str.InsertRange(0, str); }
/// <summary> /// Initializes a new instance of the <see cref="MutexNode"/> class. /// </summary> /// <param name="label">The label.</param> public AggregatorNode(string label) { _label = label; _type = ReteNodeType.Aggregator; _items = new BigList<Token>(); _inferredFacts = new List<WME>(); }
public void Insert(string username, int index, string str) { BigList <char> user_str = users.GetValue(username); cache[username].Push(new BigList <char>(user_str)); user_str.InsertRange(index, str); }
public void Delete(string username, int startIndex, int length) { BigList <char> str = users.GetValue(username); cache[username].Push(new BigList <char>(str)); str.RemoveRange(startIndex, length); }
public void Clear(string username) { BigList <char> str = users.GetValue(username); cache[username].Push(new BigList <char>(str)); str.Clear(); }
/// <summary> /// Initializes a new instance of the <see cref="BuiltinMemory"/> class. /// </summary> /// <param name="label">The label.</param> public BuiltinMemory(string label) { _label = label; _type = ReteNodeType.Builtin; _results = new List<string>(); _items = new BigList<Token>(); }
public BigList GetByPerfectSquare() { var linked = new BigList(); if (MaxEdge < MinEdge) { for (var i = MinEdge; i >= MaxEdge; i--) { var s = string.Empty; if (i > 0) { if (IsPerfectSquare((uint)i)) { s += "Circles"; } } linked.AddLast(i, !string.IsNullOrEmpty(s) ? s : i.ToString(CultureInfo.InvariantCulture)); } return(linked); } for (var i = MinEdge; i <= MaxEdge; i++) { var s = string.Empty; if (i > 0) { if (IsPerfectSquare((uint)i)) { s += "Circles"; } } linked.AddLast(i, !string.IsNullOrEmpty(s) ? s : i.ToString(CultureInfo.InvariantCulture)); } return(linked); }
public override IEnumerable <long> SelectRange(IndexRange[] ranges) { if (ranges.Length == 1 && ranges[0] == IndexRange.FullRange) { var rowList = new BigList <long>(Table.RowCount); using (var e = Table.GetEnumerator()) { while (e.MoveNext()) { DoInsertSort(rowList, e.Current.Number); } } return(rowList); } var setSize = Table.RowCount; // If no items in the set return an empty set if (setSize == 0) { return(new long[0]); } var checker = new RangeChecker(this, ranges); return(checker.Resolve()); }
/// <summary> /// Initializes a new instance of the <see cref="BuiltinMemory"/> class. /// </summary> /// <param name="label">The label.</param> public BuiltinMemory(string label) { _label = label; _type = ReteNodeType.Builtin; _results = new List <string>(); _items = new BigList <Token>(); }
private long HighestSearch(IndexKey ob, BigList <long> list, long lower, long higher) { if ((higher - lower) <= 5) { // Start from the bottom up until we find the highest val for (var i = higher; i >= lower; --i) { int res = ob.CompareTo(GetKey(list[i])); if (res >= 0) { return(i + 1); } } // Didn't find return lowest return(lower); } var mid = (lower + higher) / 2; int compResult = ob.CompareTo(GetKey(list[mid])); if (compResult == 0) { // We know the bottom is between 'mid' and 'higher' return(HighestSearch(ob, list, mid, higher)); } if (compResult < 0) { return(HighestSearch(ob, list, lower, mid - 1)); } return(HighestSearch(ob, list, mid + 1, higher)); }
private static void Add(char[] stringToAdd, BigList <char> stringContainer) { foreach (var character in stringToAdd) { stringContainer.Add(character); } }
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); }
/// <summary> /// Initializes a new instance of the Fallen-8 class. /// </summary> public Fallen8() { IndexFactory = new IndexFactory(); _graphElements = new BigList <AGraphElement>(); ServiceFactory = new ServiceFactory(this); IndexFactory.Indices.Clear(); }
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)); }
public Arguments(BigList <BigInteger> memory, Instruction ins, int opCodeArgLength, BigInteger argStartIndex, BigInteger relativeBaseOffset) { this.Arg1Index = argStartIndex; if (ins.Op == OpCode.Halt) { Arg1 = Arg2 = Arg3 = TargetIndex = 0; return; } Arg1 = ReadValue(argStartIndex, relativeBaseOffset, memory, ins.Arg1Mode); Arg2 = opCodeArgLength > 1 ? ReadValue(argStartIndex + 1, relativeBaseOffset, memory, ins.Arg2Mode) : int.MinValue; Arg3 = opCodeArgLength > 2 ? ReadValue(argStartIndex + 2, relativeBaseOffset, memory, ins.Arg3Mode) : int.MinValue; var targetArgMode = opCodeArgLength switch { 0 => ins.Arg1Mode, 1 => ins.Arg1Mode, 2 => ins.Arg2Mode, 3 => ins.Arg3Mode, _ => throw new ArgumentOutOfRangeException() }; TargetIndex = targetArgMode switch { ParameterModeEnum.ImmediateMode => argStartIndex + opCodeArgLength - 1, ParameterModeEnum.PositionMode => memory[argStartIndex + opCodeArgLength - 1], ParameterModeEnum.RelativeMode => relativeBaseOffset + memory[argStartIndex + Math.Max(opCodeArgLength, 1) - 1], _ => throw new NotImplementedException() }; }
/// <summary> ///A test for Clear ///</summary> public void ClearUnitTestHelper <T>() where T : class { var target = new BigList <T>(); // TODO: Initialize to an appropriate value target.Clear(); }
/// <summary> /// Initializes this text /// </summary> /// <param name="input">The input text</param> public StreamingText(TextReader input) { this.input = input; content = new BigList <char>(); buffer = new char[BLOCK_SIZE]; atEnd = false; }
static void Main(string[] args) { BigList <string> list = new BigList <string>(); string line = Console.ReadLine(); while (line != "End") { string[] tokens = line.Split(' '); string command = tokens[0]; if (command == "Append") { AppendClient(tokens[1]); } else if (command == "Serve") { ServeClient(int.Parse(tokens[1])); } else if (command == "Insert") { InsertClient(int.Parse(tokens[1]), tokens[2]); } else if (command == "Find") { FindClient(tokens[1]); } line = Console.ReadLine(); } result.Length--; Console.WriteLine(result.ToString()); }
static void Main() { const int InsertCount = 100000; Console.WriteLine("Start of string inserts:"); Console.WriteLine("------------------------"); var startTime = DateTime.Now; var ropeOfChars = new BigList<char>(); for (int i = 0; i < InsertCount; i++) { ropeOfChars.Insert(0, (char)('a' + (i % 10))); } Console.WriteLine("Rope<char> time: {0}", DateTime.Now - startTime); startTime = DateTime.Now; var stringBuilder = new StringBuilder(); for (int i = 0; i < InsertCount; i++) { stringBuilder.Insert(0, (char)('a' + (i % 10))); } Console.WriteLine("StringBuilder time: {0}", DateTime.Now - startTime); startTime = DateTime.Now; var ropeOfInts = new BigList<int>(); for (int i = 0; i < InsertCount; i++) { ropeOfInts.Insert(0, i); } Console.WriteLine("Rope<int> time: {0}", DateTime.Now - startTime); startTime = DateTime.Now; var listOfInts = new List<int>(); for (int i = 0; i < InsertCount; i++) { listOfInts.Insert(0, i); } Console.WriteLine("List<int> time: {0}", DateTime.Now - startTime); Console.WriteLine(); Console.WriteLine("Middle of string inserts:"); Console.WriteLine("-------------------------"); startTime = DateTime.Now; ropeOfChars = new BigList<char>(); for (int i = 0; i < InsertCount; i++) { ropeOfChars.Insert(ropeOfChars.Count / 2, (char)('a' + (i % 10))); } Console.WriteLine("Rope<char> time: {0}", DateTime.Now - startTime); startTime = DateTime.Now; stringBuilder = new StringBuilder(); for (int i = 0; i < InsertCount; i++) { stringBuilder.Insert(stringBuilder.Length / 2, (char)('a' + (i % 10))); } Console.WriteLine("StringBuilder time: {0}", DateTime.Now - startTime); }
public void Test_BigList_SouldWorkCorectly() { BigList<int> List = new BigList<int>(); Stack stack = new Stack(); stack.Push(3); stack.Push('d'); ; }
public static void ShowResults(BigList r) { Console.Clear(); Console.WriteLine(); Console.WriteLine("================================= R E S U L T S ================================"); r.PrintAll(); Console.ReadKey(); }
/// <summary> /// Initializes a new instance of the <see cref="WME"/> class. /// </summary> /// <param name="label">The label.</param> public WME(string label) { _label = label; _fields = new Term[3]; _alpha_mem_items = new BigList<ItemInAlphaMemory>(); _tokens = new BigList<Token>(); _negative_join_results = new BigList<NegativeJoinResult>(); }
/// <summary> /// Initializes a new instance of the <see cref="WME"/> class. /// </summary> /// <param name="label">The label.</param> public WME(string label) { _label = label; _fields = new Term[3]; _alpha_mem_items = new BigList <ItemInAlphaMemory>(); _tokens = new BigList <Token>(); _negative_join_results = new BigList <NegativeJoinResult>(); }
/// <summary> ///A test for SetDefault ///</summary> public void SetDefaultUnitTestHelper <T>() where T : class { var target = new BigList <T>(); // TODO: Initialize to an appropriate value int index = 0; // TODO: Initialize to an appropriate value target.SetDefault(index); }
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); }
static bool IsValidIndex(int index, BigList<char> rope) { if (index >= rope.Count || index < 0) { return false; } return true; }
private static void ReadFromConsole(BigList<char> rope) { string line = Console.ReadLine(); while (line != "PRINT") { Edit(line, rope); line = Console.ReadLine(); } }
public SuperMarker() { this.result = new StringBuilder(); this.FindByName = new Dictionary<string, int>(); this.queue = new BigList<string>(); }
public static void Main(string[] args) { var data = new BigList<char>(); Console.WriteLine("Give commands in format commans|value1|value2... etc"); var line = Console.ReadLine(); while (line != "Exit") { var tokens = line.Split('|').Select(c => c.Trim()).ToList(); var command = tokens[0]; switch (command) { case "Insert": if (tokens.Count != 2) { throw new ArgumentException("Invalid command format!"); } data.AddRangeToFront(tokens[1].ToCharArray()); Console.WriteLine("OK"); break; case "Append": if (tokens.Count != 2) { throw new ArgumentException("Invalid command format!"); } data.AddRange(tokens[1].ToCharArray()); Console.WriteLine("OK"); break; case "Delete": if (tokens.Count != 3) { throw new ArgumentException("Invalid command format!"); } data.RemoveRange(int.Parse(tokens[1]), int.Parse(tokens[2])); Console.WriteLine("OK"); break; case "Print": if (tokens.Count != 1) { throw new ArgumentException("Invalid command format!"); } foreach (var ch in data) { Console.Write(ch); } Console.WriteLine(); break; } line = Console.ReadLine(); } }
private static void TestRopeEditing(BigList<char> rope, int numOfTests) { for (int i = 0; i < numOfTests; i++) { Edit("APPEND XXX XXX", rope); Edit("INSERT @#$!@#@!#!@#!@#!@#!#!@#!@$@!$@#$#@$#@$ 5", rope); Edit("DELETE 35 15", rope); Edit("REPLACE 50 1 a", rope); } }
private static bool InsertInRope(BigList<char> rope, string input, int index) { if (rope.Count >= index) { var chars = input.ToCharArray(); rope.InsertRange(index, chars); return true; } return false; }
// Столкновение одиночного объекта с множеством снарядов public bool GameWorldCollision(ref BigList<Shell> listShells, GameObject gameObject) { for (int i = 0; i < listShells.Count; i++) if (listShells[i].Enabled && listShells[i].CollidesWith(gameObject.CollisionBounds)) { listShells[i].RestartState(); return true; } return false; }
static void Main() { BigList<char> text = new BigList<char>(); // Test 1: Console Input string input = Console.ReadLine(); while (input != "END") { string[] tokens = input.Split(' '); switch (tokens[0]) { case "APPEND": Append(text, String.Join(" ", tokens.Where(x => x != "APPEND"))); break; case "INSERT": Insert(text, Int32.Parse(tokens[1]), tokens[2]); break; case "DELETE": Delete(text, Int32.Parse(tokens[1]), Int32.Parse(tokens[2])); break; case "PRINT": Print(text); break; case "REPLACE": Replace(text, Int32.Parse(tokens[1]), Int32.Parse(tokens[2]), tokens[3]); break; } input = Console.ReadLine(); } // Test 2: Performance text = new BigList<char>(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < 1000; i++) { Append(text, "pesho", false); Append(text, "123", false); Insert(text, 0, "456", false); Delete(text, 1, 2, false); Delete(text, 0, 5 + i, false); Append(text, "pepi", false); Replace(text, 1, 5, "kiro", false); Replace(text, 0, 5 + i, "krasi", false); Delete(text, 0, 2, false); Append(text, "Hello C#", false); } stopwatch.Stop(); Console.WriteLine(); Console.WriteLine(stopwatch.Elapsed); }
private static void Delete(BigList<char> text, int position, int count, bool shouldPrint = true) { if (position < 0 || position + count >= text.Count) { PrintErrorMessage(shouldPrint); return; } text.RemoveRange(position, count); PrintSuccessMessage(shouldPrint); }
private static void Delete(BigList<char> rope, StringBuilder builder, int startIndex, int count) { try { rope.RemoveRange(startIndex, count); } catch { builder.AppendLine("ERROR"); return; } builder.AppendLine("OK"); }
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); }
static void Main() { BigList<char> rope = new BigList<char>(); //TestRopeEditing(rope, 200); //TestRopeEditing(rope, 20000); //You may want to disable (comment) line 74 as t takes forever to print the OK ReadFromConsole(rope); foreach (var ch in rope) { Console.Write(ch); } Console.WriteLine(); }
private static void Replace(BigList<char> rope, StringBuilder builder, int startIndex, int count, string value) { try { rope.RemoveRange(startIndex, count); rope.InsertRange(startIndex, value); } catch (Exception) { builder.AppendLine("ERROR"); return; } builder.AppendLine("OK"); }
private static void Insert(BigList<char> text, int position, string textToAppend, bool shouldPrint = true) { if (position < 0 || position >= text.Count) { PrintErrorMessage(shouldPrint); return; } for (int i = 0; i < textToAppend.Length; i++) { text.Insert(position + i, textToAppend[i]); } PrintSuccessMessage(shouldPrint); }
private static void Main() { queue = new BigList<string>(); occurances = new Dictionary<string, int>(); result = new StringBuilder(); string currentCommand = Console.ReadLine(); while (currentCommand != "End") { ProcessCommand(currentCommand.Split(' ')); currentCommand = Console.ReadLine(); } Console.Write(result); }
private static void Main() { var rope = new BigList<char>(); string command = string.Empty; while (command != "PRINT") { var input = Console.ReadLine().Split(' '); command = input[0].ToUpper(); switch (command) { case "INSERT": var frontChars = input[1].Select(ch => ch); rope.AddRangeToFront(frontChars); Console.WriteLine("OK"); break; case "APPEND": var endChars = input[1].Select(ch => ch); rope.AddRange(endChars); Console.WriteLine("OK"); break; case "DELETE": int startIndex = int.Parse(input[1]); int count = int.Parse(input[2]); try { rope.RemoveRange(startIndex, count); Console.WriteLine("OK"); } catch (ArgumentOutOfRangeException) { Console.WriteLine("ERROR"); } break; case "PRINT": Console.WriteLine(string.Join(string.Empty, rope)); break; default: Console.WriteLine("Invalid command."); break; } } }
public void BigList_SetValue_UnitTest() { var bigList = new BigList<Object>(); var object0 = new object(); bigList.SetValue(0, object0); var object0Actual = bigList.GetElement(0); Assert.IsTrue(ReferenceEquals(object0, object0Actual)); var object10 = new object(); bigList.SetValue(10, object10); var object10Actual = bigList.GetElement(10); Assert.IsTrue(ReferenceEquals(object10, object10Actual)); var object250000000 = new object(); bigList.SetValue(250000000, object250000000); var object250000000Actual = bigList.GetElement(250000000); Assert.IsTrue(ReferenceEquals(object250000000, object250000000Actual)); }
/// <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 Main() { Console.Write("Enter products count: "); var productsCount = int.Parse(Console.ReadLine()); Console.Write("Enter products min price: "); var minPrice = double.Parse(Console.ReadLine()); Console.Write("Enter products max price: "); var maxPrice = double.Parse(Console.ReadLine()); Console.Write("Enter subrange lower limit: "); var lowerLimit = double.Parse(Console.ReadLine()); Console.Write("Enter subrange upper limit: "); var upperLimit = double.Parse(Console.ReadLine()); bag = new OrderedMultiDictionary<double, Product>(true); products = new BigList<Product>(); rnd = new Random(); FillBag(productsCount, minPrice, maxPrice); //FillBag(10000); var subrange = bag.Range(lowerLimit, true, upperLimit, true).Take(20); FindFirstNthProduct(subrange); PrintResult(); }
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()); } }