summaryrefslogtreecommitdiff
path: root/Build/source/utils/xml2pmx/xml2pmx-src/obsrc/Fifo.m
blob: 28e208b1da48c54fa1a5ff4ad79781e19f8d392e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
MODULE Fifo;

(***************************************************************************)
(**************** Copyright 2015--2021 Dieter Gloetzel ********************)
(************************ Version016 multi platform  ***********************)
(***************************************************************************)
(*  This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>. *)

IMPORT Out; (*  := WCout; *)
VAR
TYPE 
	LONGINT = INTEGER;
  Node* = POINTER TO NodeDesc;
  NodeDesc = RECORD
  	key* : LONGINT;
  	next : Node
  END;
  FIFO* = RECORD
  		first*, last* : Node
  		END;
  slur* = POINTER TO slurlist; 	  
  slurlist* = RECORD(NodeDesc)
  id, start, stop : CHAR;
  ps, voice, measure, note : LONGINT;
  END;
 PROCEDURE smallfree*(used : SET) : LONGINT;
	  (* finds the lowest INTEGER included in "used" *)
	  VAR i : LONGINT;
	  BEGIN
	  i := -1; 
	  REPEAT INC(i); UNTIL (i IN used);
	  RETURN i;
	  END smallfree;

 PROCEDURE Enqueue*( VAR q: FIFO;  n: Node );  
	(* puts Tag "n" into the list "q" *)
	BEGIN 
		n.next := NIL;  
		IF q.first # NIL THEN q.last.next := n ELSE q.first := n END;  
		q.last := n
	END Enqueue;  
 PROCEDURE DequeuedNode*(VAR q: FIFO) : Node;
 VAR n : Node;
 BEGIN
 n := q.first;
 IF n # NIL THEN q.first := n.next END;
 RETURN n
 END DequeuedNode; 
 
PROCEDURE testfifo*;
VAR m, n : Node; q : FIFO; i : LONGINT; used : SET;
BEGIN
i := 0; 
WHILE i < 10 DO 
		NEW(n); 
		n.key := i; 
		Enqueue(q,n); 
		INC(i) 
END;

m := DequeuedNode(q); i := 0;
WHILE m # NIL DO 
	Out.Int(i,5); 
	Out.Char("|");
	Out.Int(m.key,5);
	m := DequeuedNode(q); 
	INC(i); 
END;
i := 0; 
used := {1,2,3};Out.Ln(); Out.String("1,2,3"); Out.Int(smallfree(used),5);

used := {0,2,3,4};Out.Ln(); Out.String("2,3,4"); Out.Int(smallfree(used),5);


END testfifo;
END Fifo.testfifo
System.Free Fifo