Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does julia have hashmaps like structures?

I am new to julia!I have just switched from java to julia, Can somebody tell me does julia have hashmap like structures? if No, then how do I map one type to another type in julia?

like image 315
black sheep 369 Avatar asked Sep 05 '17 03:09

black sheep 369


2 Answers

Yes!! It does have. Below is how you can create and access one inside Julia.

# Creating the Dict in Julia
julia> hashmap = Dict("language"=>"julia","version"=>"0.6")
        Dict{String,String} with 2 entries:
          "language" => "julia"
          "version"  => "0.6"

# To access individual keys
julia> hashmap["language"]
"julia"

# To find the fields inside a dictionary
julia> fieldnames(hashmap)
8-element Array{Symbol,1}:
 :slots
 :keys
 :vals
 :ndel
 :count
 :age
 :idxfloor
 :maxprobe

# To iterate over the hashmap
julia> for i in hashmap
           println(i)
       end
"language"=>"julia"
"version"=>"0.6"      
like image 103
Rahul Avatar answered Oct 06 '22 10:10

Rahul


The Julia Dict is implemented as a hashmap. As with Java, it is important to consider the interface versus the implementation.

Associative is an abstract type that roughly corresponds to Map in Java; these objects can be indexed by their keys to get the corresponding values:

value = associative[key]

Dict is a concrete subtype of Associative that is implemented as an unordered hashmap.

dict = Dict("a" => 1, "b" => 3)
@show dict["a"]  # dict["a"] = 1
like image 20
Fengyang Wang Avatar answered Oct 06 '22 10:10

Fengyang Wang