Design a system to keep top k frequent words real time

后端 未结 4 1257
有刺的猬
有刺的猬 2020-12-23 12:40

Suppose we want a system to keep top k frequent words appear in tweets in last one hour. How to design it?

I can come up with hashmap, heap, log or MapReduce but I c

4条回答
  •  难免孤独
    2020-12-23 13:30

    You can use a TreeMap which is basically a sorted hashmap. In java, you can make the TreeMap list out it's entries in descending order (by overriding the comparison method in the Comparable interface). In this case, the top k entries after the specified period of time would give you the result.

提交回复
热议问题