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_34.html
More file actions
137 lines (137 loc) · 5.87 KB
/
collections_34.html
File metadata and controls
137 lines (137 loc) · 5.87 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!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_35.html"><img border="0"
alt="ウィークハッシュテーブル" src="next.png" /></a></td>
<td bgcolor="#99CCFF"><a href="collections_23.html"><img border="0"
alt="具象可変コレクションクラス" src="up.png" /></a></td>
<td bgcolor="#99CCFF"><a href="collections_33.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-mutable-collection-classes.html">Scala Documentation</a> に移行しました。
</blockquote>
<h2>ハッシュテーブル</h2>
<p>
ハッシュテーブルは、内部で要素を配列に格納し、要素の位置はハッシュコードにより決められる。ハッシュテーブルへの要素の追加は、既に配列の中に同じハッシュコードを持つ他の要素が無い限り、定数時間で行われる。そのため、ハッシュコードの分布が適度である限り非常に高速だ。結果として、Scala
の可変マップと可変集合のデフォルトの実装はハッシュテーブルに基づいており、<a href=
"http://www.scala-lang.org/api/current/scala/collection/mutable/HashSet.html"><tt>mutable.HashSet</tt></a>
クラスと <a href=
"http://www.scala-lang.org/api/current/scala/collection/mutable/HashMap.html">
<tt>mutable.HashMap</tt></a> クラスから直接アクセスできる。</p>
<p>ハッシュ集合とハッシュマップは他の集合やマップと変りなく使うことができる。以下に具体例で説明する:</p>
<div class="quote">
<table cellspacing="1" cellpadding="0">
<tr>
<td></td>
</tr>
<tr>
<td colspan="99" align="left"><tt>scala> <font color=
"#0000E5">val</font> map = scala.collection.mutable.</tt><tt>HashMap.empty[<font color="#660099">Int</font>,<font color="#660099">String</font>]</tt></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000">map: scala.collection.mutable.</font></tt><tt><font color="#590000">HashMap[Int,String] = Map()</font></tt></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td colspan="99" align="left">
<tt>scala> map += (<font color=
"#000000">1</font> -> <font color=
"#000000">"make a web site"</font>)</tt></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000">res42: map.type = Map(1 -> make a web site)</font></tt></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td colspan="99" align="left">
<tt>scala> map += (<font color=
"#000000">3</font> -> <font color=
"#000000">"profit!"</font>)</tt></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000">res43: map.type = Map(1 -> make a web site, 3 -> profit!)</font></tt></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td colspan="99" align="left"><tt>scala> map(<font color=
"#000000">1</font>)</tt></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000">res44: String = make a web site</font></tt></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td colspan="99" align="left">
<tt>scala> map contains <font color=
"#000000">2</font></tt></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000">res46: Boolean = false</font></tt></td>
</tr>
</table>
</div>
<p>
ハッシュテーブルからの要素の取り出しは、特定の順序を保証していない。要素の取り出しは単に内部の配列を通して行われるため、順序はその時の配列の状態により決まる。要素の取り出しの順序を保証したい場合は、普通のハッシュマップではなく<em>連結</em>ハッシュマップを使うべきだ。連結ハッシュマップもしくは連結ハッシュ集合は、要素を追加した順序を保った連結リストを含む以外は普通のハッシュマップやハッシュ集合とほとんど同じだ。それにより、コレクションからの要素の取り出しは要素が追加された順序と常に一致する。</p>
<p>続いては、<a href="collections_35.html">ウィークハッシュマップ</a></p>
<hr />
<table width="100%" cellpadding="0" cellspacing="2">
<tr>
<td bgcolor="#99CCFF"><a href="collections_35.html"><img border="0"
alt="ウィークハッシュテーブル" src="next.png" /></a></td>
<td bgcolor="#99CCFF"><a href="collections_23.html"><img border="0"
alt="具象可変コレクションクラス" src="up.png" /></a></td>
<td bgcolor="#99CCFF"><a href="collections_33.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>