This repository was archived by the owner on Mar 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcollections_19.html
More file actions
61 lines (61 loc) · 3.96 KB
/
collections_19.html
File metadata and controls
61 lines (61 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<meta name="generator" content=
"HTML Tidy for Mac OS X (vers 25 March 2009), see www.w3.org" />
<title>Scala 2.8 コレクション API -- ハッシュトライ</title>
<link rel="stylesheet" type="text/css" href="guide.css" />
</head>
<body dir="ltr">
<table width="100%" cellpadding="0" cellspacing="2">
<tr>
<td bgcolor="#99CCFF"><a href="collections_20.html"><img border="0"
alt="赤黒木" src="next.png" /></a></td>
<td bgcolor="#99CCFF"><a href="collections_12.html"><img border="0"
alt="具象不変コレクションクラス" src="up.png" /></a></td>
<td bgcolor="#99CCFF"><a href="collections_18.html"><img border="0"
alt="範囲" src="previous.png" /></a></td>
<td align="center" bgcolor="#99CCFF" width="100%">
<b>ハッシュトライ</b></td>
<td bgcolor="#99CCFF" align="center" class="tocref"><a href=
"collections_49.html">目次</a></td>
</tr>
</table>
<blockquote style=
"border-left: 1px solid gray; font-family: Century, Times, 'Times New Roman', 'MS Gothic', serif; padding-left: 1em;">
最新版は <a href="http://docs.scala-lang.org/ja/overviews/collections/concrete-immutable-collection-classes.html">Scala Documentation</a> に移行しました。
</blockquote>
<h2>ハッシュトライ</h2>
<p>ハッシュトライは不変集合と不変マップを効率的に実装する標準的な方法だ。ハッシュトライは、<a href=
"http://www.scala-lang.org/api/current/scala/collection/immutable/HashMap.html"><tt>immutable.HashMap</tt></a>
クラスによりサポートされている。
データ構造は、全てのノードに 32個の要素か
32個の部分木があるという意味でベクトルに似ている。しかし、キーの選択はハッシュコードにより行われる。たとえば、マップから任意のキーを検索する場合、まずキーのハッシュコードを計算する。その後、最初の部分木を選択するのにハッシュコードの下位
5ビットが使われ、次の
5ビットで次の部分木が選択される、という具合だ。ノード内の全ての要素が、その階層までで選ばれているビット範囲内でお互いと異なるハッシュコードを持った時点で選択は終了する。</p>
<p>ハッシュトライは、サイズ相応の高速な検索と、相応に効率的な関数型加算 <tt>(+)</tt> と減算 <tt>(-)</tt>
の調度良いバランスが取れている。そのため、ハッシュトライは Scala
の不変マップと不変集合のデフォルトの実装を支えている。実は、Scala は要素が
5個未満の不変集合と不変マップに関して、更なる最適化をしている。1 〜 4個の要素を持つ集合とセットは、要素
(マップの場合は、キー/値のペア)
をフィールドとして持つ単一のオブジェクトとして格納する。空の不変集合と、空の不変マップは、ぞれぞれ単一のオブジェクトである。空の不変集合や不変マップは、空であり続けるため、データ構造を複製する必要はない。</p>
<p>続いては、<a href="collections_20.html">赤黒木</a></p>
<hr />
<table width="100%" cellpadding="0" cellspacing="2">
<tr>
<td bgcolor="#99CCFF"><a href="collections_20.html"><img border="0"
alt="赤黒木" src="next.png" /></a></td>
<td bgcolor="#99CCFF"><a href="collections_12.html"><img border="0"
alt="具象不変コレクションクラス" src="up.png" /></a></td>
<td bgcolor="#99CCFF"><a href="collections_18.html"><img border="0"
alt="範囲" src="previous.png" /></a></td>
<td align="center" bgcolor="#99CCFF" width="100%">
<b>ハッシュトライ</b></td>
<td bgcolor="#99CCFF" align="center" class="tocref"><a href=
"collections_49.html">目次</a></td>
</tr>
</table>
</body>
</html>