1 (* Indexing.def provides a dynamic indexing mechanism.
3 Copyright (C) 2015-2023 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
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)
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.
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/>. *)
22 DEFINITION MODULE Indexing ;
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 ;
32 IndexProcedure = PROCEDURE (ADDRESS) ;
36 InitIndex - creates and returns an Index.
39 PROCEDURE InitIndex (low: CARDINAL) : Index ;
43 KillIndex - returns Index to free storage.
46 PROCEDURE KillIndex (i: Index) : Index ;
50 DebugIndex - turns on debugging within an index.
53 PROCEDURE DebugIndex (i: Index) : Index ;
57 InBounds - returns TRUE if indice, n, is within the bounds
61 PROCEDURE InBounds (i: Index; n: CARDINAL) : BOOLEAN ;
65 HighIndice - returns the last legally accessible indice of this array.
68 PROCEDURE HighIndice (i: Index) : CARDINAL ;
72 LowIndice - returns the first legally accessible indice of this array.
75 PROCEDURE LowIndice (i: Index) : CARDINAL ;
79 PutIndice - places, a, into the dynamic array at position i[n]
82 PROCEDURE PutIndice (i: Index; n: CARDINAL; a: ADDRESS) ;
86 GetIndice - retrieves, element i[n] from the dynamic array.
89 PROCEDURE GetIndice (i: Index; n: CARDINAL) : ADDRESS ;
93 IsIndiceInIndex - returns TRUE if, a, is in the index, i.
96 PROCEDURE IsIndiceInIndex (i: Index; a: ADDRESS) : BOOLEAN ;
100 RemoveIndiceFromIndex - removes, a, from Index, i.
103 PROCEDURE RemoveIndiceFromIndex (i: Index; a: ADDRESS) ;
107 DeleteIndice - delete i[j] from the array.
110 PROCEDURE DeleteIndice (i: Index; j: CARDINAL) ;
114 IncludeIndiceIntoIndex - if the indice is not in the index, then
118 PROCEDURE IncludeIndiceIntoIndex (i: Index; a: ADDRESS) ;
122 ForeachIndiceInIndexDo - for each j indice of i, call procedure p(i[j])
125 PROCEDURE ForeachIndiceInIndexDo (i: Index; p: IndexProcedure) ;