Hashmap in Motoko! (Doubt)

I have a doubt ,

public type Xchange = {
    xid : Int; // Xchange Id
    posts : [Post]; // List of Posts in this Xchange

In above piece of code, i have a attribute posts as a array of post, in the same way, is there any way to declare value of some entity as a hashmap instead of array?
If there is please write an example of the same , that would be great help.

Something like:

import Hash "mo:base/Hash";
import HashMap "mo:base/HashMap";
import Nat "mo:base/Nat";

type PostId = Nat;
type Posts = HashMap.HashMap<PostId, Post>;

let posts : Posts = HashMap.HashMap(32, Nat.equal, Hash.hash);

See also HashMap :: Internet Computer and Search · HashMap · GitHub

1 Like