[erlang-questions] 2 indexes

Sean Hinde sean.hinde@REDACTED
Sat Apr 12 20:21:05 CEST 2008


On 12 Apr 2008, at 15:57, Stanisław Pitucha wrote:
> Hi
> I'm trying to do something that will effectively work as 2 indexes in
> ets. I'm writing a proxy for connections so my connection list is
> {IdForSide1, IdForSide2, OtherStuff}. I'd like to find that tuple by
> any of ids quickly... is there a way to do it with only one tuple, or
> should I split it to 3 tables {IdForSide1, ConnectionRef},
> {IdForSide2, ConnectionRef}, {ConnectionRef, OtherStuff} ?
> That seems like rather heavy solution, or maybe not... I don't have
> that much experience with ets.

You are correct. There is no way to have multiple indexes within a  
single ets table.

I would probably split it into 2 tables:

{Id1, {Id2, Stuff}}
{Id2, Id1}

If there is some bias towards the number of lookups for Id1 or Id2  
then I would make that one the one with a direct lookup to Stuff. The  
extra entry for Id2 in the first table would be to support deletions  
from either Id.

Sean




More information about the erlang-questions mailing list