Understanding HashMap

type Id = Nat32;

  type Post = {
    creater : Text;
    title : Text;
    content : Text;
  };

let posts = Map.HashMap<Id, Post>(
    0,
    Nat32.equal,
    func(a : Nat32) : Nat32 { a },
  );
Map.HashMap<Id, Post>(
    0,
    Nat32.equal,
    func(a : Nat32) : Nat32 { a },

what does this Map actually do, there’s not many examples, also what is the best way to store objects? In array or a list? Also trying to figure about how to update a post content provided by an id in function. Thanks !

I’d recommend GitHub - ZhenyaUsenko/motoko-hash-map: Stable hash maps for Motoko as you will get much better performance.

It has both sets and key value maps. It makes getting a value out of a big list much faster by using indexing by key. Your code won’t have to search through the whole list to find the item.