diff --git a/_ja/overviews/collections/overview.md b/_ja/overviews/collections/overview.md index 8cdae22a13..82a26ba556 100644 --- a/_ja/overviews/collections/overview.md +++ b/_ja/overviews/collections/overview.md @@ -53,17 +53,19 @@ Scala のコレクションは、体系的に可変および不変コレクシ 次の図は `scala.collection` パッケージ内の全てのコレクションを示す。 これらはすべて、高レベルの抽象クラスやトレイトで一般に可変と不変の両方の実装を持っている。 -[]({{ site.baseurl }}/resources/images/collections.png) +[![General collection hierarchy][1]][1] 次の図は `scala.collection.immutable` パッケージ内の全てのコレクションを示す。 -[]({{ site.baseurl }}/resources/images/collections.immutable.png) +[![Immutable collection hierarchy][2]][2] そして、次の図は `scala.collection.mutable` パッケージ内の全てのコレクションを示す。 -[]({{ site.baseurl }}/resources/images/collections.mutable.png) +[![Mutable collection hierarchy][3]][3] -(以上三つ全ての図は decodified.com の Matthias によって生成された。) +図の伝説: + +[![Graph legend][4]][4] ## コレクションAPIの概要 @@ -102,3 +104,9 @@ Scala のコレクションは、体系的に可変および不変コレクシ 唯一の例外は、可変コレクションにのみ存在する `Buffer` トレイトだ。 これより、これらのクラスを一つずつ見ていく。 + + + [1]: /resources/images/tour/collections-diagram.svg + [2]: /resources/images/tour/collections-immutable-diagram.svg + [3]: /resources/images/tour/collections-mutable-diagram.svg + [4]: /resources/images/tour/collections-legend-diagram.svg diff --git a/_overviews/FAQ/collections.md b/_overviews/FAQ/collections.md index 97ad5520a1..65f9f3d5a1 100644 --- a/_overviews/FAQ/collections.md +++ b/_overviews/FAQ/collections.md @@ -39,8 +39,9 @@ collections, which was introduced with Scala 2.9. I'll talk about them in the next section. The hierarchy described in this section refers _exclusively to non-parallel collections_. -The following image shows the non-specific hierarchy introduced with Scala 2.8: -![General collection hierarchy][5] +The following image shows the non-specific hierarchy as of Scala 2.10: + +[![General collection hierarchy][5]][5] All elements shown are traits. In the other two hierarchies there are also classes directly inheriting the traits as well as classes which can be _viewed @@ -48,14 +49,16 @@ as_ belonging in that hierarchy through implicit conversion to wrapper classes. The legend for these graphs can be found after them. Graph for immutable hierarchy: - + +[![Immutable collection hierarchy][10]][10] Graph for mutable hierarchy: - + +[![Mutable collection hierarchy][11]][11] Legend: -![Graph legend][8] +[![Graph legend][8]][8] Here's an abbreviated ASCII depiction of the collection hierarchy, for those who can't see the images. @@ -67,9 +70,11 @@ Here's an abbreviated ASCII depiction of the collection hierarchy, for those who +------------------+--------------------+ Map Set Seq | | | - | +----+----+ +-----+------+ - Sorted Map SortedSet BitSet Buffer Vector LinearSeq - + | | +------+-------+ + SortedMap SortedSet Buffer Vector LinearSeq + | + | + BitSet ## Parallel Collections @@ -282,13 +287,12 @@ it. Also available are some traits with further refinements, such as * `Set` -- A set is a collection that includes at most one of any object. - * `BitSet` -- A set of integers stored as a bitset. - * `immutable.BitSet` - * `mutable.BitSet` - * `SortedSet` -- A set whose elements are ordered. * `immutable.SortedSet` + * `immutable.BitSet` -- A set of integers stored as a bitset. * `immutable.TreeSet` -- An implementation of a `SortedSet` based on a tree. + * `mutable.SortedSet` + * `mutable.BitSet` -- A set of integers stored as a bitset. * `SetProxy` -- A `Proxy` for a `Set`. @@ -372,8 +376,10 @@ Overflow. [2]: http://docs.scala-lang.org/overviews/core/architecture-of-scala-collections.html [3]: http://www.scala-lang.org/sid/3 [4]: https://github.com/sirthias/scala-collections-charts/downloads - [5]: http://i.stack.imgur.com/bSVyA.png + [5]: /resources/images/tour/collections-diagram.svg [6]: http://i.stack.imgur.com/2fjoA.png [7]: http://i.stack.imgur.com/Dsptl.png - [8]: http://i.stack.imgur.com/szWUr.png + [8]: /resources/images/tour/collections-legend-diagram.svg [9]: http://stackoverflow.com/q/1722137/53013 + [10]: /resources/images/tour/collections-immutable-diagram.svg + [11]: /resources/images/tour/collections-mutable-diagram.svg diff --git a/_overviews/collections/overview.md b/_overviews/collections/overview.md index e0a7a33c29..a394241837 100644 --- a/_overviews/collections/overview.md +++ b/_overviews/collections/overview.md @@ -100,17 +100,19 @@ The following figure shows all collections in package `scala.collection`. These are all high-level abstract classes or traits, which generally have mutable as well as immutable implementations. -[]({{ site.baseurl }}/resources/images/collections.png) +[![General collection hierarchy][1]][1] The following figure shows all collections in package `scala.collection.immutable`. -[]({{ site.baseurl }}/resources/images/collections.immutable.png) +[![Immutable collection hierarchy][2]][2] And the following figure shows all collections in package `scala.collection.mutable`. -[]({{ site.baseurl }}/resources/images/collections.mutable.png) +[![Mutable collection hierarchy][3]][3] -(All three figures were generated by Matthias at decodified.com). +Legend: + +[![Graph legend][4]][4] ## An Overview of the Collections API ## @@ -144,3 +146,9 @@ This behavior which is implemented everywhere in the collections libraries is ca Most of the classes in the collections hierarchy exist in three variants: root, mutable, and immutable. The only exception is the Buffer trait which only exists as a mutable collection. In the following, we will review these classes one by one. + + + [1]: /resources/images/tour/collections-diagram.svg + [2]: /resources/images/tour/collections-immutable-diagram.svg + [3]: /resources/images/tour/collections-mutable-diagram.svg + [4]: /resources/images/tour/collections-legend-diagram.svg diff --git a/_zh-cn/overviews/collections/overview.md b/_zh-cn/overviews/collections/overview.md index 526d6c658f..26d5e90771 100644 --- a/_zh-cn/overviews/collections/overview.md +++ b/_zh-cn/overviews/collections/overview.md @@ -45,17 +45,19 @@ Scala 集合类系统地区分了可变的和不可变的集合。可变集合 下面的图表显示了`scala.collection`包中所有的集合类。这些都是高级抽象类或特性,它们通常具备和不可变实现一样的可变实现。 -[]({{ site.baseurl }}/resources/images/collections.png) +[![General collection hierarchy][1]][1] 下面的图表显示scala.collection.immutable中的所有集合类。 -[]({{ site.baseurl }}/resources/images/collections.immutable.png) +[![Immutable collection hierarchy][2]][2] 下面的图表显示scala.collection.mutable中的所有集合类。 -[]({{ site.baseurl }}/resources/images/collections.mutable.png) +[![Mutable collection hierarchy][3]][3] -(以上三个图表由Matthias生成, 来自decodified.com)。 +图传奇: + +[![Graph legend][4]][4] ## 集合API概述 @@ -89,3 +91,9 @@ Traversable类提供了所有集合支持的API,同时,对于特殊类型也 大多数类在集合树中存在这于三种变体:root, mutable 和immutable。唯一的例外是缓冲区特征,它仅在于mutable集合。 下面我们将一个个的回顾这些类。 + + + [1]: /resources/images/tour/collections-diagram.svg + [2]: /resources/images/tour/collections-immutable-diagram.svg + [3]: /resources/images/tour/collections-mutable-diagram.svg + [4]: /resources/images/tour/collections-legend-diagram.svg diff --git a/resources/images/tour/Makefile b/resources/images/tour/Makefile index 7e563a4bc8..ac6f9a458e 100644 --- a/resources/images/tour/Makefile +++ b/resources/images/tour/Makefile @@ -1,4 +1,18 @@ +all: unified-types\ + type-casting\ + collections\ + collections-immutable\ + collections-mutable\ + collections-legend unified-types: - dot -Tsvg unified-types-diagram.dot -o unified-types-diagram.svg + dot -Tsvg $@-diagram.dot -o $@-diagram.svg type-casting: - dot -Tsvg type-casting-diagram.dot -o type-casting-diagram.svg + dot -Tsvg $@-diagram.dot -o $@-diagram.svg +collections: + dot -Tsvg $@-diagram.dot -o $@-diagram.svg +collections-immutable: + dot -Tsvg $@-diagram.dot -o $@-diagram.svg +collections-mutable: + dot -Tsvg $@-diagram.dot -o $@-diagram.svg +collections-legend: + dot -Tsvg $@-diagram.dot -o $@-diagram.svg diff --git a/resources/images/tour/collections-diagram.dot b/resources/images/tour/collections-diagram.dot new file mode 100644 index 0000000000..ed837d3f77 --- /dev/null +++ b/resources/images/tour/collections-diagram.dot @@ -0,0 +1,22 @@ +digraph Collections { + edge [ + color="#7F7F7F" + ]; + node [ + shape="box", + style="rounded, filled", + fontcolor="#FFFFFF", + color="#6DC6E6" + ]; + rankdir="TB"; + + Traversable -> Iterable; + Iterable -> Seq; + Iterable -> Set; + Iterable -> Map; + Seq -> IndexedSeq; + Seq -> LinearSeq; + Set -> SortedSet; + SortedSet -> BitSet; + Map -> SortedMap; +} diff --git a/resources/images/tour/collections-diagram.svg b/resources/images/tour/collections-diagram.svg new file mode 100644 index 0000000000..aa2036aeb4 --- /dev/null +++ b/resources/images/tour/collections-diagram.svg @@ -0,0 +1,108 @@ + + + + + + +Collections + + +Traversable + +Traversable + + +Iterable + +Iterable + + +Traversable->Iterable + + + + +Seq + +Seq + + +Iterable->Seq + + + + +Set + +Set + + +Iterable->Set + + + + +Map + +Map + + +Iterable->Map + + + + +IndexedSeq + +IndexedSeq + + +Seq->IndexedSeq + + + + +LinearSeq + +LinearSeq + + +Seq->LinearSeq + + + + +SortedSet + +SortedSet + + +Set->SortedSet + + + + +SortedMap + +SortedMap + + +Map->SortedMap + + + + +BitSet + +BitSet + + +SortedSet->BitSet + + + + + diff --git a/resources/images/tour/collections-immutable-diagram.dot b/resources/images/tour/collections-immutable-diagram.dot new file mode 100644 index 0000000000..460913e7a6 --- /dev/null +++ b/resources/images/tour/collections-immutable-diagram.dot @@ -0,0 +1,53 @@ +digraph ImmutableCollections { + edge [ + color="#7F7F7F" + ]; + node [ + shape="box", + style="rounded, filled", + fontcolor="#FFFFFF", + color="#6DC6E6" + ]; + rankdir="TB"; + + HashSet [color="#4A5659"]; + TreeSet [color="#4A5659"]; + ListSet [color="#4A5659"]; + HashMap [color="#4A5659"]; + TreeMap [color="#4A5659"]; + ListMap [color="#4A5659"]; + Vector [color="#4A5659"]; + NumericRange [color="#4A5659"]; + String [color="#4A5659"]; + Range [color="#4A5659"]; + List [color="#4A5659"]; + Stack [color="#4A5659"]; + Stream [color="#4A5659"]; + Queue [color="#4A5659"]; + + Traversable -> Iterable [penwidth="4"]; + Iterable -> Set; + Iterable -> Seq [penwidth="4"]; + Iterable -> Map; + Set -> SortedSet; + Set -> HashSet [penwidth="4"]; + Set -> ListSet; + SortedSet -> BitSet; + SortedSet -> TreeSet; + Seq -> IndexedSeq; + Seq -> LinearSeq [penwidth="4"]; + IndexedSeq -> Vector [penwidth="4"]; + IndexedSeq -> NumericRange; + IndexedSeq -> Range; + IndexedSeq -> String [style="dashed"]; + LinearSeq -> List [penwidth="4"]; + LinearSeq -> Stack; + LinearSeq -> Stream; + LinearSeq -> Queue; + Map -> HashMap [penwidth="4"]; + Map -> ListMap; + Map -> SortedMap; + SortedMap -> TreeMap; + + {rank=same; Seq; TreeMap} +} diff --git a/resources/images/tour/collections-immutable-diagram.svg b/resources/images/tour/collections-immutable-diagram.svg new file mode 100644 index 0000000000..30e732690e --- /dev/null +++ b/resources/images/tour/collections-immutable-diagram.svg @@ -0,0 +1,248 @@ + + + + + + +ImmutableCollections + + +HashSet + +HashSet + + +TreeSet + +TreeSet + + +ListSet + +ListSet + + +HashMap + +HashMap + + +TreeMap + +TreeMap + + +ListMap + +ListMap + + +Vector + +Vector + + +NumericRange + +NumericRange + + +String + +String + + +Range + +Range + + +List + +List + + +Stack + +Stack + + +Stream + +Stream + + +Queue + +Queue + + +Traversable + +Traversable + + +Iterable + +Iterable + + +Traversable->Iterable + + + + +Set + +Set + + +Iterable->Set + + + + +Seq + +Seq + + +Iterable->Seq + + + + +Map + +Map + + +Iterable->Map + + + + +Set->HashSet + + + + +Set->ListSet + + + + +SortedSet + +SortedSet + + +Set->SortedSet + + + + +IndexedSeq + +IndexedSeq + + +Seq->IndexedSeq + + + + +LinearSeq + +LinearSeq + + +Seq->LinearSeq + + + + +Map->HashMap + + + + +Map->ListMap + + + + +SortedMap + +SortedMap + + +Map->SortedMap + + + + +SortedSet->TreeSet + + + + +BitSet + +BitSet + + +SortedSet->BitSet + + + + +IndexedSeq->Vector + + + + +IndexedSeq->NumericRange + + + + +IndexedSeq->String + + + + +IndexedSeq->Range + + + + +LinearSeq->List + + + + +LinearSeq->Stack + + + + +LinearSeq->Stream + + + + +LinearSeq->Queue + + + + +SortedMap->TreeMap + + + + + diff --git a/resources/images/tour/collections-legend-diagram.dot b/resources/images/tour/collections-legend-diagram.dot new file mode 100644 index 0000000000..8eda960d45 --- /dev/null +++ b/resources/images/tour/collections-legend-diagram.dot @@ -0,0 +1,21 @@ +digraph Legend { + edge [ + color="#7F7F7F" + ]; + node [ + label="Trait" + shape="box", + style="rounded, filled", + fontcolor="#FFFFFF", + color="#6DC6E6" + ]; + rankdir="LR"; + + Class1 [label="Class", color="#4A5659"]; + Class2 [label="Class", color="#4A5659"]; + Class3 [label="Class", color="#4A5659"]; + + Trait1 -> Class1 [label="Implemented by"]; + Trait2 -> Class2 [label="Default Implementation", penwidth="4"]; + Trait3 -> Class3 [label="via Implicit Conversion", style="dashed"]; +} diff --git a/resources/images/tour/collections-legend-diagram.svg b/resources/images/tour/collections-legend-diagram.svg new file mode 100644 index 0000000000..0c30d40176 --- /dev/null +++ b/resources/images/tour/collections-legend-diagram.svg @@ -0,0 +1,61 @@ + + + + + + +Legend + + +Class1 + +Class + + +Class2 + +Class + + +Class3 + +Class + + +Trait1 + +Trait + + +Trait1->Class1 + + +Implemented by + + +Trait2 + +Trait + + +Trait2->Class2 + + +Default Implementation + + +Trait3 + +Trait + + +Trait3->Class3 + + +via Implicit Conversion + + + diff --git a/resources/images/tour/collections-mutable-diagram.dot b/resources/images/tour/collections-mutable-diagram.dot new file mode 100644 index 0000000000..03d032eadf --- /dev/null +++ b/resources/images/tour/collections-mutable-diagram.dot @@ -0,0 +1,123 @@ +digraph MutableCollections { + edge [ + color="#7F7F7F" + ]; + node [ + shape="box", + style="rounded, filled", + fontcolor="#FFFFFF", + color="#6DC6E6" + ]; + rankdir="TB"; + + HashSet [color="#4A5659"]; + ImmutableSetAdaptor [color="#4A5659"]; + LinkedHashSet [color="#4A5659"]; + HashMap [color="#4A5659"]; + OpenHashMap [color="#4A5659"]; + WeakHashMap [color="#4A5659"]; + LinkedHashMap [color="#4A5659"]; + ListMap [color="#4A5659"]; + TreeMap [color="#4A5659"]; + ImmutableMapAdaptor [color="#4A5659"]; + ArraySeq [color="#4A5659"]; + ArrayBuffer [color="#4A5659"]; + StringBuilder [color="#4A5659"]; + ListBuffer [color="#4A5659"]; + Stack [color="#4A5659"]; + ArrayStack [color="#4A5659"]; + SynchronizedStack [color="#4A5659"]; + PriorityQueue [color="#4A5659"]; + SynchronizedPriorityQueue [color="#4A5659"]; + SynchronizedQueue [color="#4A5659"]; + MutableList [color="#4A5659"]; + LinkedList [color="#4A5659"]; + DoubleLinkedList [color="#4A5659"]; + + Traversable -> Iterable [penwidth="4"]; + Iterable -> Map; + Iterable -> Seq [penwidth="4"]; + Iterable -> Set; + Iterable -> PriorityQueue; + Map -> HashMap [penwidth="4"]; + Map -> WeakHashMap; + Map -> OpenHashMap; + Map -> LinkedHashMap; + Map -> ObservableMap; + Map -> SynchronizedMap; + Map -> ImmutableMapAdaptor; + Map -> TreeMap; + Map -> ListMap; + Map -> MultiMap; + Set -> HashSet [penwidth="4"]; + Set -> ObservableSet; + Set -> ImmutableSetAdaptor; + Set -> LinkedHashSet; + Set -> SynchronizedSet; + Set -> SortedSet; + SortedSet -> BitSet; + Seq -> LinearSeq; + Seq -> IndexedSeq [penwidth="4"]; + Seq -> Buffer; + Seq -> Stack; + Seq -> ArrayStack; + LinearSeq -> MutableList [penwidth="4"]; + LinearSeq -> LinkedList; + LinearSeq -> DoubleLinkedList; + IndexedSeq -> ArraySeq; + IndexedSeq -> StringBuilder; + IndexedSeq -> ArrayBuffer [penwidth="4"]; + Buffer -> ArrayBuffer [penwidth="4"]; + Buffer -> ObservableBuffer; + Buffer -> SynchronizedBuffer; + Buffer -> ListBuffer; + Stack -> SynchronizedStack; + PriorityQueue -> SynchronizedPriorityQueue; + MutableList -> Queue; + Queue -> SynchronizedQueue; + + {rank=same; + Iterable; + PriorityQueue; + SynchronizedPriorityQueue} + {rank=same; + Map; + Set} + {rank=same; + WeakHashMap; + LinkedHashMap; + ListMap; + ObservableMap; + ImmutableMapAdaptor; + BitSet; + LinkedHashSet; + ObservableSet; + Seq} + {rank=same; + HashMap; + OpenHashMap; + SynchronizedMap; + MultiMap; + HashSet; + ImmutableSetAdaptor; + SynchronizedSet} + {rank=same; + IndexedSeq; + Buffer; + LinearSeq; + Stack; + ArrayStack} + {rank=same; + ArraySeq; + ArrayBuffer; + SynchronizedBuffer; + SynchronizedStack; + MutableList; + LinkedList} + {rank=same; + ObservableBuffer; + StringBuilder; + ListBuffer; + Queue; + DoubleLinkedList} +} diff --git a/resources/images/tour/collections-mutable-diagram.svg b/resources/images/tour/collections-mutable-diagram.svg new file mode 100644 index 0000000000..a4e7ff4630 --- /dev/null +++ b/resources/images/tour/collections-mutable-diagram.svg @@ -0,0 +1,423 @@ + + + + + + +MutableCollections + + +HashSet + +HashSet + + +ImmutableSetAdaptor + +ImmutableSetAdaptor + + +LinkedHashSet + +LinkedHashSet + + +HashMap + +HashMap + + +OpenHashMap + +OpenHashMap + + +WeakHashMap + +WeakHashMap + + +LinkedHashMap + +LinkedHashMap + + +ListMap + +ListMap + + +TreeMap + +TreeMap + + +ImmutableMapAdaptor + +ImmutableMapAdaptor + + +ArraySeq + +ArraySeq + + +ArrayBuffer + +ArrayBuffer + + +StringBuilder + +StringBuilder + + +ListBuffer + +ListBuffer + + +Stack + +Stack + + +SynchronizedStack + +SynchronizedStack + + +Stack->SynchronizedStack + + + + +ArrayStack + +ArrayStack + + +PriorityQueue + +PriorityQueue + + +SynchronizedPriorityQueue + +SynchronizedPriorityQueue + + +PriorityQueue->SynchronizedPriorityQueue + + + + +SynchronizedQueue + +SynchronizedQueue + + +MutableList + +MutableList + + +Queue + +Queue + + +MutableList->Queue + + + + +LinkedList + +LinkedList + + +DoubleLinkedList + +DoubleLinkedList + + +Traversable + +Traversable + + +Iterable + +Iterable + + +Traversable->Iterable + + + + +Iterable->PriorityQueue + + + + +Map + +Map + + +Iterable->Map + + + + +Seq + +Seq + + +Iterable->Seq + + + + +Set + +Set + + +Iterable->Set + + + + +Map->HashMap + + + + +Map->OpenHashMap + + + + +Map->WeakHashMap + + + + +Map->LinkedHashMap + + + + +Map->ListMap + + + + +Map->TreeMap + + + + +Map->ImmutableMapAdaptor + + + + +ObservableMap + +ObservableMap + + +Map->ObservableMap + + + + +SynchronizedMap + +SynchronizedMap + + +Map->SynchronizedMap + + + + +MultiMap + +MultiMap + + +Map->MultiMap + + + + +Seq->Stack + + + + +Seq->ArrayStack + + + + +LinearSeq + +LinearSeq + + +Seq->LinearSeq + + + + +IndexedSeq + +IndexedSeq + + +Seq->IndexedSeq + + + + +Buffer + +Buffer + + +Seq->Buffer + + + + +Set->HashSet + + + + +Set->ImmutableSetAdaptor + + + + +Set->LinkedHashSet + + + + +ObservableSet + +ObservableSet + + +Set->ObservableSet + + + + +SynchronizedSet + +SynchronizedSet + + +Set->SynchronizedSet + + + + +SortedSet + +SortedSet + + +Set->SortedSet + + + + +BitSet + +BitSet + + +SortedSet->BitSet + + + + +LinearSeq->MutableList + + + + +LinearSeq->LinkedList + + + + +LinearSeq->DoubleLinkedList + + + + +IndexedSeq->ArraySeq + + + + +IndexedSeq->ArrayBuffer + + + + +IndexedSeq->StringBuilder + + + + +Buffer->ArrayBuffer + + + + +Buffer->ListBuffer + + + + +ObservableBuffer + +ObservableBuffer + + +Buffer->ObservableBuffer + + + + +SynchronizedBuffer + +SynchronizedBuffer + + +Buffer->SynchronizedBuffer + + + + +Queue->SynchronizedQueue + + + + +