如何存储大量独特的条目?
我正在尝试一个项目,该项目要求我记录用户访问的每个唯一的 URL,目标是有一种方法来存储每个数组以保持它们的唯一性。
有没有有效的方法来做到这一点?
显然,这在理论上可能是巨大的,如果它是一个数组,则可能有数万个条目,这是不行的——我该如何存储它们?
I am attempting a project which requires me to record each unique URL visited by the user, with the goal being to have a way of storing each array to keep them unique.
Is there an efficient way to do this?
Obviously this could be theoretically massive, possibly tens of thousands of entries if it was an array which would not do - how might I go about storing them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
数组可以包含数万甚至数十万个元素。
但为了唯一性,您需要一个
Set< /code>
而不是数组,因为与数组上的线性查找时间相比,它提供了亚线性查找时间,并且为唯一值集提供了更好的语义。
这是一个构建一百万个唯一值集的示例-随机的数字:
对我来说,运行时间约为 200 毫秒。而在几分钟后我放弃了使用数组的等效方法。
Arrays can contain tens of thousands, or even hundreds of thousands, of elements.
But for uniqueness, you want a
Set
rather than an array, as it offers sub-linear lookup time compared to linear lookup time on an array, and better semantics for sets of unique values..Here's an example building a set of a million unique otherwise-random numbers:
For me, that runs in about 200ms. Whereas I gave up on the equivalent using an array after several minutes.