Difference between revisions of "Referencerecord"

From Mesham
Jump to navigationJump to search
(Created page with '== Syntax == referencerecord[name<sub>1</sub>, type<sub>1</sub>,name<sub>2</sub>,type<sub>2</sub>,...,name<sub>d</sub>,type<sub>d</sub>] == Semantics == The record type ma…')
 
(Example)
Line 21: Line 21:
 
     head:=newnode;
 
     head:=newnode;
 
  };
 
  };
 
+
 
  while (head != null)
 
  while (head != null)
 
  {
 
  {

Revision as of 21:35, 10 January 2010

Syntax

referencerecord[name1, type1,name2,type2,...,named,typed]

Semantics

The record type may NOT refer to itself (or other records) where as reference records support this, allowing the programmer to create data structures such as linked lists and trees. There are some added complexities of reference records, such as communicating them (all links and linking nodes will be communicated with the record) and freeing the data (garbage collection.) This results in a slight performance hit and is the reason why the record concept has been split into two types.

Example

var node:referencerecord["prev",node,"Int",data,"next",node];
var head:node;
head:=null;
var i;
for i from 0 to 9
{
   var newnode:node;
   newnode.data:=i;
   newnode.next:=head;
   if (head!=null) head.prev:=newnode;
   head:=newnode;
};

while (head != null)
{
   print[head.data,"\n"];
   head:=head.next;
};

In this code example a doubly linked list is created, and then its contents read node by node.