This patch introduces the procedure function FindIndice to library
module Indexing.
gcc/m2/ChangeLog:
* gm2-libs/Indexing.def (FindIndice): New procedure
function.
* gm2-libs/Indexing.mod (FindIndice): Implement new
procedure function.
Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
PROCEDURE IsEmpty (i: Index) : BOOLEAN ;
+(*
+ FindIndice - returns the indice containing a.
+ It returns zero if a is not found in array i.
+*)
+
+PROCEDURE FindIndice (i: Index; a: ADDRESS) : CARDINAL ;
+
+
END Indexing.
END IncludeIndiceIntoIndex ;
+(*
+ FindIndice - returns the indice containing a.
+ It returns zero if a is not found in array i.
+*)
+
+PROCEDURE FindIndice (i: Index; a: ADDRESS) : CARDINAL ;
+VAR
+ j: CARDINAL ;
+ p: PtrToAddress ;
+ b: PtrToByte ;
+BEGIN
+ WITH i^ DO
+ j := Low ;
+ b := ArrayStart ;
+ WHILE j <= High DO
+ p := VAL (PtrToAddress, b) ;
+ INC (b, TSIZE (ADDRESS)) ;
+ IF p^ = a
+ THEN
+ RETURN j
+ END ;
+ INC (j)
+ END
+ END ;
+ RETURN 0
+END FindIndice ;
+
+
(*
ForeachIndiceInIndexDo - for each j indice of i, call procedure p(i[j])
*)