在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:JuliaCollections/FunctionalCollections.jl开源软件地址:https://github.com/JuliaCollections/FunctionalCollections.jl开源编程语言:Julia 100.0%开源软件介绍:FunctionalCollectionsFunctional and persistent data structures for Julia. This is a work in progress and is currently not optimized for performance. NOTE: The Installationjulia> Pkg.add("FunctionalCollections")
julia> using FunctionalCollections Exports
src/FunctionalCollections.jl contains all of the package's exports, though many built-ins are also implemented. PersistentVectorPersistent vectors are immutable, sequential, random-access data structures, with performance characteristics similar to arrays. julia> v = @Persistent [1, 2, 3, 4, 5]
Persistent{Int64}[1, 2, 3, 4, 5] Since persistent vectors are immutable, "changing" operations return a new vector instead of modifying the original. julia> append(v, [6, 7])
Persistent{Int64}[1, 2, 3, 4, 5, 6, 7]
# v hasn't changed
julia> v
Persistent{Int64}[1, 2, 3, 4, 5] Persistent vectors are random-access structures, and can be indexed into just like arrays. julia> v[3]
3 But since they're immutable, it doesn't make sense to define index
assignment ( julia> assoc(v, 3, 42)
Persistent{Int64}[1, 2, 42, 4, 5] Three functions, julia> push(v, 6)
Persistent{Int64}[1, 2, 3, 4, 5, 6]
julia> peek(v)
5
julia> pop(v)
Persistent{Int64}[1, 2, 3, 4] Persistent vectors also support iteration and higher-order sequence operations. julia> for el in @Persistent ["foo", "bar", "baz"]
println(el)
end
foo
bar
baz
julia> map(x -> x * 2, v)
Persistent{Int64}[2, 4, 6, 8, 10]
julia> filter(iseven, v)
Persistent{Int64}[2, 4] PersistentHashMapPersistent hash maps are immutable, unordered, associative structures,
similar to the built-in julia> name = @Persistent Dict(:first => "Zach", :last => "Allaun")
Persistent{Symbol, String}[last => Allaun, first => Zach] They can be queried in a manner similar to the dictionaries. julia> name[:first]
"Zach"
julia> get(name, :middle, "")
"" With persistent vectors, julia> fullname = assoc(name, :middle, "Randall")
Persistent{Symbol, String}[last => Allaun, first => Zach, middle => Randall]
julia> dissoc(fullname, :middle)
Persistent{Symbol, String}[last => Allaun, first => Zach]
julia> mapkeys(f, m::PersistentHashMap) =
map(kv -> (f(kv[1]), kv[2]), m)
julia> mapkeys(string, fullname)
Persistent{String, String}[last => Allaun, middle => Randall, first => Zach] PersistentArrayMapPersistentArrayMaps are immutable dictionaries implemented as Arrays of key-value pairs. This means that the time complexity of most operations on them is O(n). They can be quickly created, though, and useful at small sizes. julia> m = PersistentArrayMap((1, "one"))
Persistent{Int64, String}Pair{Int64,String}[1=>"one"]
julia> m2 = assoc(m, 2, "two")
Persistent{Int64, String}Pair{Int64,String}[1=>"one", 2=>"two"]
julia> m == m2
false
julia> dissoc(m2, 2)
Persistent{Int64, String}Pair{Int64,String}[1 => one]
julia> m == dissoc(m2, 2)
true PersistentSetPersistentSets are immutable sets. Along with the usual set interface,
TODO:General
# currently
pvec([1,2,3,4,5])
pset(1,2,3,4,5)
# should be
pvec(1,2,3,4,5)
pset(1,2,3,4,5)
@Persistent Dict("foo" => 1, "bar" => 2, "baz" => 3)
# creates a phmap
@Persistent [1, 2, 3, 4, 5]
# creates a pvec PersistentQueue
BitmappedTrie
PersistentVector
PersistentHashMap
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论