Skip to content

Commit ce829ab

Browse files
committed
Updated readme.
1 parent f804a84 commit ce829ab

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Build Status](https://travis-ci.org/tkoolen/TypeSortedCollections.jl.svg?branch=master)](https://travis-ci.org/tkoolen/TypeSortedCollections.jl)
44
[![codecov.io](http://codecov.io/github/tkoolen/TypeSortedCollections.jl/coverage.svg?branch=master)](http://codecov.io/github/tkoolen/TypeSortedCollections.jl?branch=master)
55

6-
TypeSortedCollections provides the `TypeSortedCollection` type, which can be used to store type-heterogeneous data in a way that allows operations on the data to be performed in a type-stable manner. It does so by sorting a type-heterogeneous input collection by type upon construction, and storing these elements in a `Tuple` of concretely typed `Vector`s, one for each type. TypeSortedCollections provides type stable methods for `map!`, `foreach`, and `mapreduce` that take at least one `TypeSortedCollection`.
6+
TypeSortedCollections provides the `TypeSortedCollection` type, which can be used to store type-heterogeneous data in a way that allows operations on the data to be performed in a type-stable manner. It does so by sorting a type-heterogeneous input collection by type upon construction, and storing these elements in a `Tuple` of concretely typed `Vector`s, one for each type. TypeSortedCollections provides type stable methods for `map!`, `foreach`, `broadcast!`, and `mapreduce` that take at least one `TypeSortedCollection`.
77

88
An example:
99
```julia
@@ -40,7 +40,7 @@ Note that construction of a `TypeSortedCollection` is of course not type stable,
4040
See also [FunctionWrappers.jl](https://github.com/yuyichao/FunctionWrappers.jl) for a solution to the related problem of storing and calling multiple callables in a type-stable manner, and [Unrolled.jl](https://github.com/cstjean/Unrolled.jl) for a macro-based solution.
4141

4242
# Iteration order
43-
By default, `TypeSortedCollection`s do not preserve iteration order, in the sense that the order in which elements are processed in `map!`, `foreach`, and `mapreduce` will not be the same as if these functions were called on the original type-heterogeneous vector:
43+
By default, `TypeSortedCollection`s do not preserve iteration order, in the sense that the order in which elements are processed in `map!`, `foreach`, `broadcast!`, and `mapreduce` will not be the same as if these functions were called on the original type-heterogeneous vector:
4444
```julia
4545
julia> xs = Number[1.; 2; 3.];
4646

@@ -75,7 +75,7 @@ julia> results = similar(xs);
7575
julia> map!(identity, results, sortedxs) # results of applying `identity` end up in the right location
7676
3-element Array{Number,1}:
7777
1.0
78-
2
78+
2
7979
3.0
8080
```
8181

@@ -105,3 +105,24 @@ julia> map!(*, results, sortedxs, sortedys)
105105
9.0
106106
16.0
107107
```
108+
109+
# Broadcasting
110+
Broadcasting (in place) is implemented for `AbstractVector` return types:
111+
```julia
112+
julia> x = 4;
113+
114+
julia> ys = Number[1.; 2; 3];
115+
116+
julia> sortedys = TypeSortedCollection(ys);
117+
118+
julia> results = similar(ys, Float64);
119+
120+
julia> results .= x .* sortedys
121+
3-element Array{Float64,1}:
122+
4.0
123+
8.0
124+
12.0
125+
126+
julia> @allocated results .= x .* sortedys
127+
0
128+
```

0 commit comments

Comments
 (0)