измени методы оставив названия методов и смыслы методов "public void Add(int id, string…
- User
измени методы оставив названия методов и смыслы методов "public void Add(int id, string documentText) { string[] words = documentText.Split(charsForSplit); wordsAndPosByIndex.Add(id, new Dictionary<string, List>());
codeint currentPos = 0; foreach (string word in words) { if (!indexesByWord.ContainsKey(word)) indexesByWord[word] = new HashSet<int>(); if (!indexesByWord[word].Contains(id)) indexesByWord[word].Add(id); if (!wordsAndPosByIndex[id].ContainsKey(word)) wordsAndPosByIndex[id].Add(word, new List<int>()); wordsAndPosByIndex[id][word].Add(currentPos); currentPos += word.Length + 1; } } public List<int> GetIds(string word) { return indexesByWord.ContainsKey(word) ? indexesByWord[word].ToList() : new List<int>(); } public List<int> GetPositions(int id, string word) { List<int> positions = new List<int>(); if (wordsAndPosByIndex.ContainsKey(id) && wordsAndPosByIndex[id].ContainsKey(word)) positions = wordsAndPosByIndex[id][word]; return positions; } public void Remove(int id) { string[] words = wordsAndPosByIndex[id].Keys.ToArray(); foreach (var word in words) indexesByWord[word].Remove(id); wordsAndPosByIndex.Remove(id); }" - Assistant
Оставив названия методов, но изменяя их функциональность, представленные методы могут быть изменены следующим образом:
public void AddWord(int id, string documentText) { string[] words = documentText.Split(charsForSplit); wordsAndPosByIndex.Add(id, new Dictionary<string, List>());
codeint currentPos = 0; foreach (string word in words) { if (!indexesByWord.ContainsKey(word)) indexesByWord[word] = new HashSet<int>(); if (!indexesByWord[word].Contains(id)) indexesByWord[word].Add(id); if (!wordsAndPosByIndex[id].ContainsKey(word)) wordsAndPosByIndex[id].Add(word, new List<int>()); wordsAndPosByIndex[id][word].Add(currentPos); currentPos += word.Length + 1; }