什么是 TrieMap,与 HashMap 相比,它的优点/缺点是什么? [英] What is a TrieMap and what is its advantages/disadvantages compared to a HashMap?

查看:49
本文介绍了什么是 TrieMap,与 HashMap 相比,它的优点/缺点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Scala 有一个 TrieMap 集合.

Scala has a TrieMap collection.

什么是 TrieMap,它与 HashMap 相比有哪些优点/缺点?

What is a TrieMap and what is its advantages/disadvantages compared to a HashMap?

推荐答案

A Scala TrieMap 是一种基于 Trie 的 并发 可扩展地图实现.与普通的 trie 映射不同,Scala TrieMap 具有高效、非阻塞、O(1) 时间的 snapshot 操作(以及稍微优化的 readOnlySnapshot) 操作.

A Scala TrieMap is a trie-based concurrent scalable map implementation. Unlike normal trie maps, a Scala TrieMap has an efficient, non-blocking, O(1) time snapshot operation (and a slightly optimized readOnlySnapshot) operation.

TrieMap 的绝对性能略低于 JDK8 ConcurrentHashMap,但优点是它提供了一致迭代器,即并发数据结构通常没有.这意味着您可以在一个时间点捕获 trie 中的所有元素(性能数据和分析 此处).如果您需要一次捕获所有元素(例如,在 UI 中列出其所有元素,或一致地分析它们),则应使用 TrieMap.

Absolute performance of a TrieMap is slightly below the JDK8 ConcurrentHashMap, but the advantage is that it provides consistent iterators, something that concurrent data structures typically do not have. This means that you can capture all the elements in the trie at one point in time (performance numbers and analysis here). You should use the TrieMap if you need to capture all the elements at once (e.g. to list all its elements in the UI, or to consistently analyze them).

这篇关于什么是 TrieMap,与 HashMap 相比,它的优点/缺点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆