# Custom dictionary type: fieldless keytype, fieldless valtype

**URL:** <https://discourse.julialang.org/t/custom-dictionary-type-fieldless-keytype-fieldless-valtype/128405>\
**Category:** General Usage\
**Tags:** dictionary, dictionaries\
**Created:** [April 25, 2025, 2:13pm UTC](https://discourse.julialang.org/t/custom-dictionary-type-fieldless-keytype-fieldless-valtype/128405 "2025-04-25T14:13:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [April 25, 2025, 2:13pm UTC](https://discourse.julialang.org/t/custom-dictionary-type-fieldless-keytype-fieldless-valtype/128405/1 "2025-04-25T14:13:11Z")

</div>

Suppose there are some `mutable struct` types with no fields, and with the default (fallback) equality and hashing methods. A value of such a type has its identity as its only quality. For example:

```julia
mutable struct A end
mutable struct B end

```

Looking for a generic `AbstractDict` subtype with such fieldless types as keys and values. What’s a good way to implement such a dictionary type, assuming the special properties of the identity-only types may be exploited for achieving better performance.

To be specific, I’m asking for this:

```julia
"""
    D{A, B} <: AbstractDict{A, B}

Both `A` and `B` is assumed to be a `mutable struct` type without any field, and with the default, identity-based, equality and default, objectid-based, hashing.
"""
struct D{A, B} <: AbstractDict{A, B}
    # ...
end
# ...

```

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [April 25, 2025, 6:52pm UTC](https://discourse.julialang.org/t/custom-dictionary-type-fieldless-keytype-fieldless-valtype/128405/2 "2025-04-25T18:52:42Z")

</div>

What’s wrong with `Dict{A,B}`?

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [April 25, 2025, 8:07pm UTC](https://discourse.julialang.org/t/custom-dictionary-type-fieldless-keytype-fieldless-valtype/128405/3 "2025-04-25T20:07:50Z")

</div>

Should `IdDict` just work for this?

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [April 25, 2025, 9:06pm UTC](https://discourse.julialang.org/t/custom-dictionary-type-fieldless-keytype-fieldless-valtype/128405/4 "2025-04-25T21:06:21Z")

</div>

> [@cjdoris](#):
>
> What’s wrong with `Dict{A,B}`?

Nothing’s wrong with it, I’m just wondering about the most efficient approach.

> [@aplavin](#):
>
> Should `IdDict` just work for this?

Possibly. ~~I suppose `IdDict` is exactly what I’m asking for~~ , on the side of the keys. I still wonder if there’s a better approach when the value type can be assumed to have the stated properties, too. EDIT: scratch that, it seems to be backed by an untyped container, `Memory{Any}`. That seems like it would limit the performance.
