为Web服务器设计数据结构以存储访问页面的历史记录

Kar*_*hik 7 algorithm data-structures

服务器必须维护最近n天的数据.它必须首先显示当前访问量最多的页面,然后显示第二天访问量最大的页面,依此类推.

我正在考虑哈希映射的哈希映射.有什么建议 ?

Den*_*aub 4

外部哈希映射,键为日期类型,值为哈希映射类型。

内部哈希映射,其中包含 url 的 string 类型的键和包含访问计数的 int 类型的值。

C# 中的示例:

// Outer hash map    
var visitsByDay = 
    new Dictionary<DateTime, VisitsByUrl>(currentDate, new VisitsByUrl());

...

// inner hash map
public class VisitsByUrl
{
    public Dictionary<string, int> Urls { get; set; }

    public VisitsByUrl()
    {
        Urls = new Dictionary<string, int>();
    }

    public void Add(string url)
    {
        if (Urls[url] != null)
            Urls[url] += 1;
        else
            Urls.Add(url, 1);
    }
}
Run Code Online (Sandbox Code Playgroud)