开发者

In what languages, associative arrays are implemented using redblack tree instead of hashtable?

开发者 https://www.devze.com 2023-01-15 13:10 出处:网络
In wi开发者_开发问答kipedia: http://en.wikipedia.org/wiki/Red-black_tree#Applications_and_related_data_structures

In wi开发者_开发问答kipedia: http://en.wikipedia.org/wiki/Red-black_tree#Applications_and_related_data_structures

red-black tree is a type of self-balancing binary search tree, a data structure used in computing science, typically used to implement associative arrays.

Anyone know a language implemented associative array using redblack tree?


java.util.TreeMap is an implementation of a red-black tree in Java.


C++ std::map is often implemented as red-black tree. It's the basic associative array. The other one (new) is std::unordered_map and is in fact a hash-map.


In C# SortedDictionary is implemented as Red-Black tree, while Dictionary uses hashtable and SortedList is basically list with binary search for keys lookup.


I don't know if it's a red-black tree, but Haskell's Data.Map is a balanced binary tree:

The implementation of Map is based on size balanced binary trees (or trees of bounded balance) as described by:

  • Stephen Adams, "Efficient sets: a balancing act", Journal of Functional Programming 3(4):553-562, October 1993, http://www.swiss.ai.mit.edu/~adams/BB/.
  • J. Nievergelt and E.M. Reingold, "Binary search trees of bounded balance", SIAM journal of computing 2(1), March 1973.

Ocaml has both a mapping type ontop of hashtables and a binary trees.


Scala's scala.collection.immutable.TreeMap is implemented with a Red-Black tree.

0

精彩评论

暂无评论...
验证码 换一张
取 消