public string DeleteProductsByNameAndProducer(string productAndProducer) { if (!this.productsByNameAndProducer.ContainsKey(productAndProducer)) { return(notFound); } else { HashSet <Product> productsToDelete = new HashSet <Product>(this.productsByNameAndProducer[productAndProducer]); int productsCount = productsToDelete.Count; StringBuilder sb = new StringBuilder(); foreach (var product in productsToDelete) { sb.Append(product.Name); sb.Append(product.Producer); productsByName.Remove(product.Name, product); productsByPrice.Remove(product.Price, product); productsByNameAndProducer.Remove(sb.ToString(), product); productsByProducer.Remove(product.Producer, product); sb = new StringBuilder(); } return(string.Format("{0} products deleted", productsCount)); } }
/// <summary> /// Updates the command process. /// </summary> /// <param name="tokens">The tokens.</param> private static void UpdateCommandProcess(string line) { string[] urls = line.Split(';'); string oldUrl = urls[0].Trim(); string newUrl = urls[1].Trim(); if (contentUrls.ContainsKey(oldUrl)) { int count = 0;//contentUrls[oldUrl].Count; foreach (var item in contentUrls[oldUrl].ToArray()) { contents.Remove(item.Title, item); item.Url = newUrl; contents.Add(item.Title, item); count++; contentUrls.Add(item.Url, item); } contentUrls.Remove(oldUrl); sb.AppendLine(count + " items updated"); } else { sb.AppendLine("0 items updated"); } }
static string DeleteProducts(string[] parameters) { int result = 0; if (parameters.Length == 1) { var matchedProducts = productsByProducer[parameters[0]]; foreach (var product in matchedProducts) { productsByName.Remove(product.Name, product); productsByNameAndProducer.Remove( new Tuple <string, string>(product.Name, product.Producer), product ); productsByPrice.Remove(product.Price, product); } result = matchedProducts.Count; productsByProducer.Remove(parameters[0]); } else if (parameters.Length == 2) { var nameAndProducer = new Tuple <string, string>(parameters[0], parameters[1]); var matchedProducts = productsByNameAndProducer[nameAndProducer]; foreach (var product in matchedProducts) { productsByName.Remove(product.Name, product); productsByProducer.Remove(product.Producer, product); productsByPrice.Remove(product.Price, product); } result = matchedProducts.Count; productsByNameAndProducer.Remove(nameAndProducer); } if (result == 0) { return("No products found"); } return(string.Format("{0} products deleted", result)); }
private static void RemoveEachProduct(ICollection <Product> productsToRemove) { foreach (var p in productsToRemove.ToList()) { productsByName.Remove(p.Name, p); productsByPrice.Remove(p.Price, p); productsByProducer.Remove(p.Producer, p); productsByNameAndProducer.Remove(p.Name + "-" + p.Producer, p); } }
private string DeleteProductsByNameAndProducer(string name, string producer) { string nameAndProducerKey = name + ";" + producer; var productsToBeRemoved = productsByNameAndProducer[nameAndProducerKey]; if (productsToBeRemoved.Any()) { int countOfRemovedProducts = productsToBeRemoved.Count; foreach (var product in productsToBeRemoved) { productsByName.Remove(product.Name, product); productsByProducer.Remove(product.Producer, product); productsByPrice.Remove(product.Price, product); } productsByNameAndProducer.Remove(nameAndProducerKey); return(countOfRemovedProducts + X_PRODUCTS_DELETED); } return(NO_PRODUCTS_FOUND); }
public ICollection <T> Remove(K1 key1, K2 key2, T value) { bool foundFirst = orderedCollectionByKey1.ContainsKey(key1); bool foundSecond = orderedCollectionByKey2.ContainsKey(key2); if (foundFirst && foundSecond) { orderedCollectionByKey1.Remove(key1); orderedCollectionByKey2.Remove(key2); } return(null); }
public string DeleteProducts(string name, string producer) { int counter = 0; string key = name + ";" + producer; if (allProductsByNameAndProducer.ContainsKey(key)) { foreach (var item in allProductsByNameAndProducer[key]) { counter++; allProductsByName.Remove(item.Name, item); allProductsByProducer.Remove(item.Producer, item); allProductsByPrice.Remove(item.Price, item); } allProductsByNameAndProducer.Remove(key); return(counter + " products deleted"); } else { return("No products found"); } }
private string DeleteProducts(string name, string producer) { string nameAndProducerKey = name + ";" + producer; if (!nameAndProducer.ContainsKey(nameAndProducerKey)) { return(NO_PRODUCTS_FOUND); } else { var productsToBeRemoved = nameAndProducer[nameAndProducerKey]; foreach (var product in productsToBeRemoved) { productsByName.Remove(name, product); productsByProducer.Remove(producer, product); productsByPrice.Remove(product.Price, product); } int countOfRemovedProducts = nameAndProducer[nameAndProducerKey].Count; nameAndProducer.Remove(nameAndProducerKey); string countMessage = countOfRemovedProducts + X_PRODUCTS_DELETED; return(countMessage); } }
/// <summary> /// Получает самые частоиспользуемые в тексте слова и заявляет,что они ключевые /// </summary> /// <returns></returns> private string GetKeywords() { var dictWordCount = GetDictionary(); var count = dictWordCount.Count; var keys = new List <string>(count); var vals = new List <int>(count); var trueVals = new List <int>(count); foreach (var i in dictWordCount) { keys.Add(i.Key); vals.Add(i.Value); trueVals.Add(i.Value); } var stemmer = _inputText.IndexOfAny("абвгдеёжзиёклмнопрстуфхцчшщьыъэюя".ToCharArray()) == -1 ? (IStemmer) new EnglishStemmer() : new RussianStemmer(); for (var i = 1; i < count; i++) { if (stemmer.Stem(keys[i]) != stemmer.Stem(keys[i - 1])) { continue; } if (keys[i].Length > keys[i - 1].Length || trueVals[i] < trueVals[i - 1]) { keys[i] = keys[i - 1]; trueVals[i] = trueVals[i - 1]; } vals[i] += vals[i - 1]; keys.RemoveAt(i - 1); vals.RemoveAt(i - 1); trueVals.RemoveAt(i-- - 1); count--; } var keyWords = new OrderedMultiDictionary <int, string> (true, (i, i1) => - i.CompareTo(i1), (s, s1) => String.Compare(s, s1, StringComparison.Ordinal)); for (var i = 0; i < count; i++) { keyWords.Add(vals[i], keys[i]); if (i > 10) { keyWords.Remove(keyWords.Last().Key, keyWords.Last().Value.Last()); } } var keywords = keyWords.SelectMany(i => i.Value).Aggregate("", (current, j) => current + (j + "+")); File.CreateText("./programfiles/top_ten.fail").Write(keywords); return(keywords); }
private static void RemoveLastScore() { if (scoreboard.Last().Value.Count > 0) { string[] values = new string[scoreboard.Last().Value.Count]; scoreboard.Last().Value.CopyTo(values, 0); scoreboard.Last().Value.Remove(values.Last()); } else { int[] keys = new int[scoreboard.Count]; scoreboard.Keys.CopyTo(keys, 0); scoreboard.Remove(keys.Last()); } }
static void main(string[] args) { OrderedMultiDictionary<int, string> tasks = new OrderedMultiDictionary<int, string>(true); StringBuilder sb = new StringBuilder(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string inputCmd = Console.ReadLine(); if (inputCmd.StartsWith("N")) { string[] input = inputCmd.Split(new char[] { ' ' }, 3); string cmd = input[0].Trim(); int complexity = int.Parse(input[1].Trim()); string name = input[2].Trim(); tasks.Add(complexity, name); } else { int tasksCount = tasks.Count; if (tasksCount == 0) { sb.AppendLine("Rest"); } else { int key = 0; foreach (var item in tasks) { key = item.Key; } string name = null; foreach (var item in tasks[key]) { name = item; } sb.AppendLine(name); tasks.Remove(key, name); } } } Console.Write(sb.ToString()); }
public void Add(double val) { OrderedMultiDictionary <interval, int> .View view = dictionary.Range(new interval(val - precision), false, new interval(val + precision), false); foreach (interval intv in view.Keys) { intv.adjustPeriodic(ref val, period, precision); if (intv.accept(val, precision)) { int count = dictionary[intv].First(); // es gibt ja nur ein int dictionary.Remove(intv); intv.expand(val); dictionary.Add(intv, count + 1); return; // fertig } } // es wurde nicht zugefügt dictionary.Add(new interval(val), 1); }
static void OrderedMultiDictionaryExample() { Console.WriteLine("Wintellect.PowerCollections.OrderedMultiDictionary<K, V> example:"); Console.WriteLine("Map keys to multiple values. Keys are ordered in ascending order. Values keep their insertion order."); OrderedMultiDictionary <string, int> score = new OrderedMultiDictionary <string, int>(true); score.Add("Peter", 5); score.Add("Peter", 6); score.Add("Peter", 6); score.AddMany("Maria", new int[] { 5, 5, 4, 6 }); score.AddMany("George", new int[] { 6, 6, 5 }); score.AddMany("Paula", new int[] { 6, 6, 5, 6 }); score.AddMany("Steve", new int[] { 5, 6 }); Console.WriteLine("Elements: {0}", score); Console.WriteLine("Removed element `Maria -> 4`: {0}", score.Remove("Maria", 4)); Console.WriteLine("Elements: {0}", score); Console.WriteLine("Range[`k`...`r`]: {0}", score.Range("k", true, "r", true)); }
public string UpdateItem(string oldUrl, string newUrl) { if (!itemsByUrl.ContainsKey(oldUrl)) { return("0 items updated"); } else { IEnumerable <Item> itemsToUpdate = new List <Item>(itemsByUrl[oldUrl]); int updateCount = itemsToUpdate.Count(); foreach (var item in itemsToUpdate) { var newItem = new Item(item.Title, item.Author, item.Size, newUrl, item.Type); itemsByUrl.Add(newUrl, newItem); itemsByTitle.Remove(item.Title, item); itemsByTitle.Add(item.Title, newItem); } itemsByUrl.Remove(oldUrl); return(string.Format("{0} items updated", updateCount)); } }
private static void ExecuteDeleteCommand(string token) { string[] curent = token.Split(';'); var producer = string.Empty; var name = string.Empty; int counter = 0; if (curent.Length == 1) { producer = curent[0]; if (prodDict.ContainsKey(producer)) { counter = prodDict[producer].Count; prodDict.Remove(producer); } } else { name = curent[0]; producer = curent[1]; if (prodDict.ContainsKey(producer)) { foreach (var item in prodDict.Values) { if (item.Producer == producer && item.Name == name) { prodDict.Values.Remove(item); counter++; } } } } output.Append(string.Format("{0} products deleted", counter)); output.Append(Environment.NewLine); }
void WipeDemand(float index, ProductItem item) { currentDemand.Remove(index, item); currentDemand.Add(0f, item); }
IEnumerator FindPath(Vector2 startPos, Vector2 desPos) { playerRect.position = desPos + player.offset; bool arrive = false; if (CollisionCheck()) { desPos = ConjecturingDestination(desPos); playerRect.position = desPos + player.offset; if (CollisionCheck()) { Debug.LogWarning("Player Can Not Go There"); findingPath = false; StopAllCoroutines(); PathFindingFailed(); arrive = true; } } float time = 0f; findingPath = true; startPos.x = Mathf.Round(startPos.x); startPos.y = Mathf.Round(startPos.y); OrderedMultiDictionary <float, PathInfo> openPaths = new OrderedMultiDictionary <float, PathInfo>(true); List <PathInfo> closedPath = new List <PathInfo>(); Dictionary <Vector2, PathInfo> S = new Dictionary <Vector2, PathInfo>(); openPaths.Add(Mathf.Round(Vector2.Distance(startPos, desPos)), new PathInfo(startPos, null)); S.Add(startPos, new PathInfo(startPos, null)); while (!arrive && openPaths.Count > 0) { time += Time.smoothDeltaTime; if (time >= 1.0f) { StopAllCoroutines(); PathFindingFailed(); break; } for (int i = 0; i < 50; i += 1) { KeyValuePair <float, PathInfo> curPath = new KeyValuePair <float, PathInfo>(); foreach (var iter in openPaths) { float key = iter.Key; PathInfo info = null; foreach (var valIter in iter.Value) { info = valIter; break; } curPath = new KeyValuePair <float, PathInfo>(key, info); break; } openPaths.Remove(curPath.Key); if (DebuggingObj != null) { DebuggingObj.transform.localPosition = curPath.Value.pos; } if (Vector2.Distance(curPath.Value.pos, desPos) <= movementDistance) { desPos.x = Mathf.Round(desPos.x); desPos.y = Mathf.Round(desPos.y); findingPath = false; MakePath(new PathInfo(desPos, curPath.Value)); arrive = true; StopAllCoroutines(); break; } var paths = GetPossibleDes(curPath.Value.pos); for (int j = 0; j < 8; j += 1) { paths[j].x = Mathf.Round(paths[j].x); paths[j].y = Mathf.Round(paths[j].y); playerRect.position = paths[j] + player.offset; if (CollisionCheck()) { continue; } float distance = Vector2.Distance(paths[j], desPos); if (S.ContainsKey(paths[j])) { PathInfo info; S.TryGetValue(paths[j], out info); if (info.befPath != null) { float otherDis = Vector2.Distance(info.pos, desPos); float thisDis = Vector2.Distance(paths[j], desPos); if (thisDis < otherDis) { S.Remove(paths[j]); S.Add(paths[j], new PathInfo(paths[j], curPath.Value)); openPaths.Remove(Mathf.Round(otherDis)); openPaths.Add(Mathf.Round(thisDis), new PathInfo(paths[j], curPath.Value)); } } } else { if (DebuggingObj != null) { DebuggingObj.transform.localPosition = paths[j]; } openPaths.Add(Mathf.Round(Vector2.Distance(paths[j], desPos)), new PathInfo(paths[j], curPath.Value)); } } } yield return(null); } }