thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Reiss <dre...@facebook.com>
Subject Re: Recursive data structures
Date Sun, 26 Oct 2008 22:47:35 GMT
One way of doing it is to use integers as pointers instead of recursive
containment.  For example...

struct Thing {
  1: optional string value;
  2: optional map<string,i32> hash;
}

typedef list<Thing> BunchOfHashes;

struct TopLevel {
  1: BunchOfHashes hashes;
  2: i32 top;
}

Then you build something like...

TopLevel {
  hashes = [
    Thing { value = 'b' },
    Thing { value = 'd' },
    Thing { hash = {'c': 1} },
    Thing { hash = {'a': 0, 'b': 2} },
  ],
  top = 3,
}

Basically, the ints the the "hash" map in "Thing" are indexes into the
"hashes" list.

There is also a patch out for review to add a variant type that would
make something like this pretty easy.

There's been talk of writing support for forward declarations, but AFAIK
no one is working on it.

--David

Hector Yuen wrote:
> hello, I am also interested in that, I have been in the need to transport
> hashes of hashes
> 
> {'a':'b', 'b':{'c':'d'}}
> 
> So far the only thing I have accomplished is to store the hashes as blobs,
> but this cannot be transported between languages
> 
> Is it possible to do something like that?
> 
> -h
> 
> On Sun, Oct 26, 2008 at 6:01 AM, Leon Mergen <l.p.mergen@solatis.com> wrote:
> 
>> Hello,
>>
>>
>> I can imagine this being asked before, but I have a little problem: I need
>> to use Thrift to transport recursive (tree-like) data structures. Is this at
>> all possible ? Have any efforts been made to implement this functionality ?
>>
>> To illustrate the use case, this is an example of what I'm trying to
>> achieve:
>>
>>
>> struct node {
>>        1:string id,
>>        2:map <string, node> children
>> }
>>
>>
>> And, ofcourse, Thrift generates the error "Type "node" has not been
>> defined".
>>
>> Any thoughts ?
>>
>>
>> Regards,
>>
>> Leon Mergen
>>
> 
> 
> 
> --
> -h

Mime
View raw message