[erlang-questions] Noddy question on hashing

Garrett Smith g@REDACTED
Thu Jul 25 17:57:51 CEST 2013


Hi Rick,

On Thu, Jul 25, 2013 at 3:52 AM, Rick Payne <rickp@REDACTED> wrote:
> Hi,
>
> I've been using erlang for some simple projects, and really enjoying it.
> However, when thinking about some of the things I'd like to do - I'm
> struggling a bit with hashing and how to handle that in a concurrent way in
> erlang. This is probably 101 stuff, sorry...
>
> Imagine we have a set of data streams giving us objects and attributes.
> Attributes can be a few kB but typically are less than 1kB. The objects are
> unique but some set of them share the attributes. Typically in C, I'm used
> to hashing the attributes and pointing at them from the objects. We hash to
> save memory and refcount so we know when we can delete from the hash. The
> good news is that the attributes are never updated in place, apart from the
> refcount.
>
> However, I'm struggling to get my head around how I'd do this in erlang
> efficiently. Any suggestions?

What specifically would you be doing in C? With more specific
operations in mind, it'll be easier to point you toward something in
Erlang I think.

Without knowing much here, I'd list two facilities in Erlang. The
first is somewhat blunt and might not be appropriate but it's an easy
way to hash something largish like a 1K attribute:

http://www.erlang.org/doc/man/erlang.html#md5-1

And this is a way to maintain your reference counts associated with hashes:

http://erlang.org/doc/man/ets.html

Garrett



More information about the erlang-questions mailing list