# a tree structure with Bro records

**URL:** <https://community.zeek.org/t/a-tree-structure-with-bro-records/1268>\
**Category:** Zeek\
**Created:** [November 29, 2007, 7:01pm UTC](https://community.zeek.org/t/a-tree-structure-with-bro-records/1268 "2007-11-29T19:01:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Wood](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@Mike\_Wood](https://community.zeek.org/u/Mike_Wood)\
**Post date:** [November 29, 2007, 7:01pm UTC](https://community.zeek.org/t/a-tree-structure-with-bro-records/1268/1 "2007-11-29T19:01:49Z")

</div>

Hello,

I would like to build a tree data structure to track flows at  
different aggregate granularities. However, I cannot seem to construct  
a recursive record structure.

The following...

type tree\_node : record {  
&nbsp;&nbsp;&nbsp;&nbsp;data : count;  
&nbsp;&nbsp;&nbsp;&nbsp;parent : tree\_node;  
};

... will lead to...

$ bro tree.bro  
./tree.bro, line 3 and ./tree.bro, line 5  
&nbsp;&nbsp;&nbsp;(tree\_node): error, not a BRO type

... and changing the parent type to 'any' and doing anything w/ the record...

type tree\_node : record {  
&nbsp;&nbsp;&nbsp;&nbsp;data : count;  
&nbsp;&nbsp;&nbsp;&nbsp;parent : any;  
};

event bro\_init () {  
&nbsp;&nbsp;&nbsp;&nbsp;local tn : tree\_node;  
&nbsp;&nbsp;&nbsp;&nbsp;tn$data = 0;  
&nbsp;&nbsp;&nbsp;&nbsp;tn$parent = tn;  
}

... will lead to...

$ bro tree.bro  
./tree.bro, line 12 (tn$parent = tn): error, type clash in assignment

... because you cannot assign to 'any' type variables, I guess.

So... just wondering if there is some other scheme / mechanism to  
build such a tree in Bro, or am I just out-of-luck.

Thanks,  
Mike

---

<div class="post-metadata">

**Author:** ![Vern](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/vern/32/630_2.png) [@Vern](https://community.zeek.org/u/Vern)\
**Post date:** [November 30, 2007, 5:52pm UTC](https://community.zeek.org/t/a-tree-structure-with-bro-records/1268/2 "2007-11-30T17:52:01Z")

</div>

> So... just wondering if there is some other scheme / mechanism to  
> build such a tree in Bro, or am I just out-of-luck.

I'm afraid closer to just-out-of-luck.

You could fake it up using table[string] of XYZ, where XYZ records include  
a string that point back into the table. Not pretty, but seems it should  
work.

&nbsp;&nbsp;&nbsp;&nbsp;Vern

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/zeek/original/1X/f09d732bc2cc7c7cc7e35db67cf4e1d5233ce7a7.png) [@system](https://community.zeek.org/u/system)\
**Post date:** [May 6, 2022, 3:38pm UTC](https://community.zeek.org/t/a-tree-structure-with-bro-records/1268/3 "2022-05-06T15:38:26Z")

</div>


