Pergunta

InMemoryCookieStore is the default CookieStore of java , but the main store is a ArrayList, the add and remove op will cost O(n) in worst case ,and index is map , which scan the keySet in order to remove expired cookie. why it use tree(which can represent domain very well,like .b.com is the parent of .a.b.com ) and set (locate Cookie in constant time) .

Foi útil?

Solução

The CookieStore has a method

List<HttpCookie> getCookies()

so it must maintain, or copy all the cookies on demand. I assume they decided that maintaining a list was the most efficient.

Outras dicas

How often do you have so many cookies that O(n) is noticeably larger than O(1) in terms of performance? When choosing between sub-optimization and code manageability, most go for clean, manageable code.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top