# Parameter -\> equal : (X, X) in Buffer Documentation

**URL:** <https://forum.dfinity.org/t/parameter-equal-x-x-in-buffer-documentation/17428>\
**Category:** Developers\
**Created:** [December 14, 2022, 9:18pm UTC](https://forum.dfinity.org/t/parameter-equal-x-x-in-buffer-documentation/17428 "2022-12-14T21:18:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![passio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/passio/32/8091_2.png) [@passio](https://forum.dfinity.org/u/passio)\
**Post date:** [December 14, 2022, 9:18pm UTC](https://forum.dfinity.org/t/parameter-equal-x-x-in-buffer-documentation/17428/1 "2022-12-14T21:18:14Z")

</div>

Hello, sorry for this probably easy question but i can’t find the solution.

I add some Principals in a Buffer and I would like to remove duplicates Principals… There is many way to do, but Buffer methods always need the equal : (X, X) parameter… And I don’t know what is that and I didn’t easily find examples.

```auto
let buff : Buffer.Buffer<Principal> = Buffer.Buffer(10);
[...]
let principal1 = "xxxx-xxxx-..." 
let principal2 = "xxxx-xxxx-..." 

if( Buffer.contains(buff, principal1, ???) == false) // check if the principal is in the buffer
{
buff.add(principal1); //add if it's not
}

```

 ![Capture d’écran 2022-12-14 à 22.21.56](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/1/16c52b446a00bc92b36fbcfdcf0346681c1f1698.png)

How can I properly use these methods please ? Could you give an easy example like this one ?

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [December 14, 2022, 11:16pm UTC](https://forum.dfinity.org/t/parameter-equal-x-x-in-buffer-documentation/17428/2 "2022-12-14T23:16:27Z")

</div>

The type signature for `equal` is `(X, X) -> Bool` which means it is a function that takes 2 arguments of type `X` and returns a `Bool`.

In this case `X` is `Principal` so you can use `Principal.equal`:

> <https://github.com/dfinity/motoko-base/blob/57b47c7747bc6fb9665095e0c8972740ef5093e1/src/Principal.mo#L32-L33>

If you never want duplicates you could consider using a `Set` data structure instead. I could only find this implementation:

> <https://github.com/dfinity/motoko-base/blob/57b47c7747bc6fb9665095e0c8972740ef5093e1/src/TrieSet.mo#L22-L22>

---

<div class="post-metadata">

**Author:** ![passio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/passio/32/8091_2.png) [@passio](https://forum.dfinity.org/u/passio)\
**Post date:** [December 14, 2022, 11:43pm UTC](https://forum.dfinity.org/t/parameter-equal-x-x-in-buffer-documentation/17428/3 "2022-12-14T23:43:33Z")

</div>

Thank you for this answer. This is was I tried to use : Principal.equal, as I used it to instanciate my Hashmaps, so, the problem is not from there…

Ok, I found immediately so, I had just forget to put var x = before my method :  
`var x = Buffer.contains(buff, q2.answers[i].principal, Principal.equal);`

Thank you also for the explanation about Set, it seems to be what I was looking for !

---

<div class="post-metadata">

**Author:** ![passio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/passio/32/8091_2.png) [@passio](https://forum.dfinity.org/u/passio)\
**Post date:** [December 15, 2022, 12:12am UTC](https://forum.dfinity.org/t/parameter-equal-x-x-in-buffer-documentation/17428/4 "2022-12-15T00:12:47Z")

</div>

I’m also unable to use this… I understand a little better these methods than before… But not perfectly yet.

 ![Capture d’écran 2022-12-15 à 01.06.08](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/8/8471575e74367b8c1729d306de471d845cfb99c4.png)

I tried :

 ![Capture d’écran 2022-12-15 à 01.10.12](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/9/98deb80ffca5443e67efc3b9ff591ca10e8351f5.png)  
I get the error :  
 ![Capture d’écran 2022-12-15 à 01.10.40](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/b/b79b1cdd61f5c8bc614d056e60158cce8a21d565.png)

I don’t really understand why it expect Nat32 type instead of Hash type like it’s written in the prototype.

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [December 15, 2022, 3:21am UTC](https://forum.dfinity.org/t/parameter-equal-x-x-in-buffer-documentation/17428/5 "2022-12-15T03:21:25Z")

</div>

The argument `xh` has the type `Hash`. If we follow the imports we can see that that’s a type alias for `Nat32`:

> <https://github.com/dfinity/motoko-base/blob/57b47c7747bc6fb9665095e0c8972740ef5093e1/src/Hash.mo#L8-L9>

You’re providing `Hash.hash`, which is a function that takes a `Nat` and returns a `Hash`:

> <https://github.com/dfinity/motoko-base/blob/57b47c7747bc6fb9665095e0c8972740ef5093e1/src/Hash.mo#L27-L27>

Instead, you probably want to provide the equivalent of `Principal.hash(q2.answers[i].principal)` for that argument.

> <https://github.com/dfinity/motoko-base/blob/57b47c7747bc6fb9665095e0c8972740ef5093e1/src/Principal.mo#L28-L28>

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [December 15, 2022, 5:55am UTC](https://forum.dfinity.org/t/parameter-equal-x-x-in-buffer-documentation/17428/6 "2022-12-15T05:55:49Z")

</div>

Evginey’s hashmap has a set implementation: [GitHub - ZhenyaUsenko/motoko-hash-map: Stable hash maps for Motoko](https://github.com/ZhenyaUsenko/motoko-hash-map)

---

<div class="post-metadata">

**Author:** ![passio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/passio/32/8091_2.png) [@passio](https://forum.dfinity.org/u/passio)\
**Post date:** [December 17, 2022, 5:32pm UTC](https://forum.dfinity.org/t/parameter-equal-x-x-in-buffer-documentation/17428/7 "2022-12-17T17:32:15Z")

</div>

Thanks 🙏 ✨ very much
