| 1 |
MODULE Fifo; |
| 2 |
|
| 3 |
(***************************************************************************) |
| 4 |
(**************** Copyright 2015--2021 Dieter Gloetzel ********************) |
| 5 |
(************************ Version016 multi platform ***********************) |
| 6 |
(***************************************************************************) |
| 7 |
(* This program is free software: you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation, either version 3 of the License, or |
| 10 |
(at your option) any later version. |
| 11 |
|
| 12 |
This program is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with this program. If not, see <http://www.gnu.org/licenses/>. *) |
| 19 |
|
| 20 |
IMPORT Out; (* := WCout; *) |
| 21 |
VAR |
| 22 |
TYPE |
| 23 |
LONGINT = INTEGER; |
| 24 |
Node* = POINTER TO NodeDesc; |
| 25 |
NodeDesc = RECORD |
| 26 |
key* : LONGINT; |
| 27 |
next : Node |
| 28 |
END; |
| 29 |
FIFO* = RECORD |
| 30 |
first*, last* : Node |
| 31 |
END; |
| 32 |
slur* = POINTER TO slurlist; |
| 33 |
slurlist* = RECORD(NodeDesc) |
| 34 |
id, start, stop : CHAR; |
| 35 |
ps, voice, measure, note : LONGINT; |
| 36 |
END; |
| 37 |
PROCEDURE smallfree*(used : SET) : LONGINT; |
| 38 |
(* finds the lowest INTEGER included in "used" *) |
| 39 |
VAR i : LONGINT; |
| 40 |
BEGIN |
| 41 |
i := -1; |
| 42 |
REPEAT INC(i); UNTIL (i IN used); |
| 43 |
RETURN i; |
| 44 |
END smallfree; |
| 45 |
|
| 46 |
PROCEDURE Enqueue*( VAR q: FIFO; n: Node ); |
| 47 |
(* puts Tag "n" into the list "q" *) |
| 48 |
BEGIN |
| 49 |
n.next := NIL; |
| 50 |
IF q.first # NIL THEN q.last.next := n ELSE q.first := n END; |
| 51 |
q.last := n |
| 52 |
END Enqueue; |
| 53 |
PROCEDURE DequeuedNode*(VAR q: FIFO) : Node; |
| 54 |
VAR n : Node; |
| 55 |
BEGIN |
| 56 |
n := q.first; |
| 57 |
IF n # NIL THEN q.first := n.next END; |
| 58 |
RETURN n |
| 59 |
END DequeuedNode; |
| 60 |
|
| 61 |
PROCEDURE testfifo*; |
| 62 |
VAR m, n : Node; q : FIFO; i : LONGINT; used : SET; |
| 63 |
BEGIN |
| 64 |
i := 0; |
| 65 |
WHILE i < 10 DO |
| 66 |
NEW(n); |
| 67 |
n.key := i; |
| 68 |
Enqueue(q,n); |
| 69 |
INC(i) |
| 70 |
END; |
| 71 |
|
| 72 |
m := DequeuedNode(q); i := 0; |
| 73 |
WHILE m # NIL DO |
| 74 |
Out.Int(i,5); |
| 75 |
Out.Char("|"); |
| 76 |
Out.Int(m.key,5); |
| 77 |
m := DequeuedNode(q); |
| 78 |
INC(i); |
| 79 |
END; |
| 80 |
i := 0; |
| 81 |
used := {1,2,3};Out.Ln(); Out.String("1,2,3"); Out.Int(smallfree(used),5); |
| 82 |
|
| 83 |
used := {0,2,3,4};Out.Ln(); Out.String("2,3,4"); Out.Int(smallfree(used),5); |
| 84 |
|
| 85 |
|
| 86 |
END testfifo; |
| 87 |
END Fifo.testfifo |
| 88 |
System.Free Fifo |