Skip to content

Instantly share code, notes, and snippets.

@milktrader
Created December 3, 2013 03:28
Show Gist options
  • Save milktrader/7763432 to your computer and use it in GitHub Desktop.
Save milktrader/7763432 to your computer and use it in GitHub Desktop.
sort SerialArray
abstract AbstractSeries
immutable SerialPair{T, V} <: AbstractSeries
index::T
value::V
end
type SerialArray{T,V} <: AbstractSeries
collection::Array{SerialPair{T,V},1} # this prevents arrays of mixed types
idxname::String
valname::String
end
# construct a SerialArray
foo = SerialPair(1, 10); bar = SerialPair(12, 15); baz = SerialPair(4, 459)
sa = SerialArray([foo, bar, baz])
# show code not provided, but this is what it looks like:
index values
1 10
12 15
4 459
# and we need an inner constructor that enforces the array is sorted by the index field of the SerialPair
@milktrader
Copy link
Author

julia> using DataSeries, Datetime

julia> foo = SerialPair(today(), 10); bar = SerialPair(today()-days(1), 15); baz = SerialPair(today()+days(1), 459)
2013-12-04  459

julia> sa  = SerialArray([foo, bar, baz])
index  values
2013-12-03  10
2013-12-02  15
2013-12-04  459

julia> sort(sa)
index  values
2013-12-02  15
2013-12-03  10
2013-12-04  459

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment