[Info-vax] DEC Basic and dynamic memory ?

Arne Vajhøj arne at vajhoej.dk
Sat Jan 29 13:20:59 EST 2022


On 1/29/2022 12:16 AM, Dave Froble wrote:
> On 1/28/2022 8:33 PM, Arne Vajhøj wrote:
>> On 1/28/2022 2:57 PM, Simon Clubley wrote:
>>> How easy is it in DEC Basic to build a tree of (say) 1000 nodes of
>>> a custom data structure in dynamic memory and then walk the tree
>>> either depth-first or breadth-first ?
>>>
>>> I've had a quick look at the dynamic storage section of the DEC Basic 
>>> user
>>> manual, but I don't see how you link a set of nodes together into a 
>>> tree.
>>> However, as mentioned previously, I don't know DEC Basic and searching
>>> for the word pointer didn't reveal anything appropriate, so I assume
>>> it's another keyword I am not aware of.
>>>
>>> In addition, how easy is this to do if the nodes are not all of the
>>> same record type, but have a common tag at the start of each record
>>> to say what kind of record it actually is ? I see you have variant
>>> records in DEC Basic. Do they also work in a dynamic memory based
>>> tree structure ?

 >> $ typ tree.bas
 >> record treenoderec

 >> $ typ dyn.bas
 >> program dyn
 >>
 >> %include "tree.bas"

 > I have difficulty following your code examples.

If I were to try to explain the code then I needed 3 things.

1) a tree structure

which I did with an array of records and using element indexes
instead of traditional pointers/addresses.

>> record treenoderec
...
>>    long pnode
>>    long lnode
>>    long rnode
>> end record

 >> declare long top
 >> declare long capacity

 >> dim treenoderec tree (1 to capacity)

 >> sub tree_insert(treenoderec tree(), long top, ...)

 >> sub tree_print(treenoderec tree())

2) dynamic allocation

which I did with DIM when the trees backing array needed
to be extended.

 >>     if top = capacity then
 >>         gosub extend_tree_array
 >>     end if

 >> extend_tree_array:
 >> dim treenoderec temp(1 to capacity)
 >> for j = 1 to capacity
 >>     temp(j) = tree(j)
 >> next j
 >> capacity = 2 * capacity
 >> dim treenoderec tree (1 to capacity)
 >> for j = 1 to capacity / 2
 >>     tree(j) = temp(j)
 >> next j
 >> return

3) support for different types (C union, Pascal case record)

which I did with MAP and MAP DYNAMIC.

 >> record treenoderec
...
 >>    long styp
 >>    string s = 512
...
 >> end record

 >> declare integer constant STRING_TYP = 1
 >> declare integer constant INTEGER_TYP = 2
 >> declare integer constant DECIMAL_TYP = 3

>> map (u) string sv = 512
>> map dynamic (u) long iv
>> map dynamic (u) decimal zv

Arne



More information about the Info-vax mailing list