1 (* Indexing.def provides a dynamic indexing mechanism for CARDINAL.
3 Copyright (C) 2003-2024 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 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. *)
27 DEFINITION MODULE Indexing ;
29 FROM SYSTEM IMPORT ADDRESS ;
30 EXPORT QUALIFIED Index, InitIndex, KillIndex, GetIndice, PutIndice,
31 HighIndice, LowIndice, InBounds, IsIndiceInIndex,
32 RemoveIndiceFromIndex, IncludeIndiceIntoIndex,
33 ForeachIndiceInIndexDo, DeleteIndice, DebugIndex ;
37 IndexProcedure = PROCEDURE (ADDRESS) ;
41 InitIndex - creates and returns an Index.
44 PROCEDURE InitIndex (low: CARDINAL) : Index ;
48 KillIndex - returns Index to free storage.
51 PROCEDURE KillIndex (i: Index) : Index ;
55 DebugIndex - turns on debugging within an index.
58 PROCEDURE DebugIndex (i: Index) : Index ;
62 InBounds - returns TRUE if indice, n, is within the bounds
66 PROCEDURE InBounds (i: Index; n: CARDINAL) : BOOLEAN ;
70 HighIndice - returns the last legally accessible indice of this array.
73 PROCEDURE HighIndice (i: Index) : CARDINAL ;
77 LowIndice - returns the first legally accessible indice of this array.
80 PROCEDURE LowIndice (i: Index) : CARDINAL ;
84 PutIndice - places, a, into the dynamic array at position i[n]
87 PROCEDURE PutIndice (i: Index; n: CARDINAL; a: ADDRESS) ;
91 GetIndice - retrieves, element i[n] from the dynamic array.
94 PROCEDURE GetIndice (i: Index; n: CARDINAL) : ADDRESS ;
98 IsIndiceInIndex - returns TRUE if, a, is in the index, i.
101 PROCEDURE IsIndiceInIndex (i: Index; a: ADDRESS) : BOOLEAN ;
105 RemoveIndiceFromIndex - removes, a, from Index, i.
108 PROCEDURE RemoveIndiceFromIndex (i: Index; a: ADDRESS) ;
112 DeleteIndice - delete i[j] from the array.
115 PROCEDURE DeleteIndice (i: Index; j: CARDINAL) ;
119 IncludeIndiceIntoIndex - if the indice is not in the index, then
123 PROCEDURE IncludeIndiceIntoIndex (i: Index; a: ADDRESS) ;
127 ForeachIndiceInIndexDo - for each j indice of i, call procedure p(i[j])
130 PROCEDURE ForeachIndiceInIndexDo (i: Index; p: IndexProcedure) ;