英文:
Dealing with big memory chunks in GO
问题
有没有描述Go如何有效处理以下用例的指南:
- 应用程序接收到包含分隔名称的1亿个字符串,每个名称最长为1M。例如:"Ben;Aaron;Rich;Donna..."。需要按字母顺序打印出相同的名称,而不会显著增加内存使用量(假设总共使用不超过150M的RAM)。
- 给定两个具有大内存块的集合(每个集合最多1M),需要有效地将几个块从一个集合移动到另一个集合(不需要显著的额外内存分配)。
英文:
Are there any guidelines which describe how Go may effectively address following use cases :
- Application receives 100M string consisting of delimited names, each name up to 1M long. E.g.: "Ben;Aaron;Rich;Donna...". Need to print out the same names in alphabet order without significant memory usage increase (let's say up to 150M RAM used in total)
- Given two collections with huge memory chunks (let's say up to 1M each) and need to effectively move few chunks from one collection to the other (without significant additional memory allocation)
答案1
得分: 1
- 我假设你不能修改字符串,所以字符串是不可变的(不是 []byte),因为去除任何这样的限制会使任务变得简单。如果是这样的话,你可以创建一个额外的结构,其中包含字符串索引,并在其中进行排序(n*log(n) 时间复杂度)。只需实现
Less
方法,使其比较原始字符串中的子字符串。 - 第二个问题很简单 - 只需使用链表。
英文:
- I assume that you cannot modify the string so the string and the string is immutable (not []byte), because removing any of such limitations makes the task trivial. If so, then you can create additional structure with string indices and sort in it (n*log(n)) time. Just implement
Less
in a way it compares the substrings in original string. - The second one is trivial - just use linked list.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论