| 1 |
(* Indexing.def provides a dynamic indexing mechanism. |
| 2 |
|
| 3 |
Copyright (C) 2015-2025 Free Software Foundation, Inc. |
| 4 |
Contributed by Gaius Mulley <[email protected]>. |
| 5 |
|
| 6 |
This file is part of GNU Modula-2. |
| 7 |
|
| 8 |
GNU Modula-2 is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 3, or (at your option) |
| 11 |
any later version. |
| 12 |
|
| 13 |
GNU Modula-2 is distributed in the hope that it will be useful, but |
| 14 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with GNU Modula-2; see the file COPYING3. If not see |
| 20 |
<http://www.gnu.org/licenses/>. *) |
| 21 |
|
| 22 |
DEFINITION MODULE Indexing ; |
| 23 |
|
| 24 |
FROM SYSTEM IMPORT ADDRESS ; |
| 25 |
EXPORT QUALIFIED Index, InitIndex, KillIndex, GetIndice, PutIndice, |
| 26 |
HighIndice, LowIndice, InBounds, IsIndiceInIndex, |
| 27 |
RemoveIndiceFromIndex, IncludeIndiceIntoIndex, |
| 28 |
ForeachIndiceInIndexDo, DeleteIndice, DebugIndex ; |
| 29 |
|
| 30 |
TYPE |
| 31 |
Index ; |
| 32 |
IndexProcedure = PROCEDURE (ADDRESS) ; |
| 33 |
|
| 34 |
|
| 35 |
(* |
| 36 |
InitIndex - creates and returns an Index. |
| 37 |
*) |
| 38 |
|
| 39 |
PROCEDURE InitIndex (low: CARDINAL) : Index ; |
| 40 |
|
| 41 |
|
| 42 |
(* |
| 43 |
KillIndex - returns Index to free storage. |
| 44 |
*) |
| 45 |
|
| 46 |
PROCEDURE KillIndex (i: Index) : Index ; |
| 47 |
|
| 48 |
|
| 49 |
(* |
| 50 |
DebugIndex - turns on debugging within an index. |
| 51 |
*) |
| 52 |
|
| 53 |
PROCEDURE DebugIndex (i: Index) : Index ; |
| 54 |
|
| 55 |
|
| 56 |
(* |
| 57 |
InBounds - returns TRUE if indice, n, is within the bounds |
| 58 |
of the dynamic array. |
| 59 |
*) |
| 60 |
|
| 61 |
PROCEDURE InBounds (i: Index; n: CARDINAL) : BOOLEAN ; |
| 62 |
|
| 63 |
|
| 64 |
(* |
| 65 |
HighIndice - returns the last legally accessible indice of this array. |
| 66 |
*) |
| 67 |
|
| 68 |
PROCEDURE HighIndice (i: Index) : CARDINAL ; |
| 69 |
|
| 70 |
|
| 71 |
(* |
| 72 |
LowIndice - returns the first legally accessible indice of this array. |
| 73 |
*) |
| 74 |
|
| 75 |
PROCEDURE LowIndice (i: Index) : CARDINAL ; |
| 76 |
|
| 77 |
|
| 78 |
(* |
| 79 |
PutIndice - places, a, into the dynamic array at position i[n] |
| 80 |
*) |
| 81 |
|
| 82 |
PROCEDURE PutIndice (i: Index; n: CARDINAL; a: ADDRESS) ; |
| 83 |
|
| 84 |
|
| 85 |
(* |
| 86 |
GetIndice - retrieves, element i[n] from the dynamic array. |
| 87 |
*) |
| 88 |
|
| 89 |
PROCEDURE GetIndice (i: Index; n: CARDINAL) : ADDRESS ; |
| 90 |
|
| 91 |
|
| 92 |
(* |
| 93 |
IsIndiceInIndex - returns TRUE if, a, is in the index, i. |
| 94 |
*) |
| 95 |
|
| 96 |
PROCEDURE IsIndiceInIndex (i: Index; a: ADDRESS) : BOOLEAN ; |
| 97 |
|
| 98 |
|
| 99 |
(* |
| 100 |
RemoveIndiceFromIndex - removes, a, from Index, i. |
| 101 |
*) |
| 102 |
|
| 103 |
PROCEDURE RemoveIndiceFromIndex (i: Index; a: ADDRESS) ; |
| 104 |
|
| 105 |
|
| 106 |
(* |
| 107 |
DeleteIndice - delete i[j] from the array. |
| 108 |
*) |
| 109 |
|
| 110 |
PROCEDURE DeleteIndice (i: Index; j: CARDINAL) ; |
| 111 |
|
| 112 |
|
| 113 |
(* |
| 114 |
IncludeIndiceIntoIndex - if the indice is not in the index, then |
| 115 |
add it at the end. |
| 116 |
*) |
| 117 |
|
| 118 |
PROCEDURE IncludeIndiceIntoIndex (i: Index; a: ADDRESS) ; |
| 119 |
|
| 120 |
|
| 121 |
(* |
| 122 |
ForeachIndiceInIndexDo - for each j indice of i, call procedure p(i[j]) |
| 123 |
*) |
| 124 |
|
| 125 |
PROCEDURE ForeachIndiceInIndexDo (i: Index; p: IndexProcedure) ; |
| 126 |
|
| 127 |
|
| 128 |
END Indexing. |