added the Find function in h3-arrays.adb
This commit is contained in:
		| @ -320,8 +320,32 @@ package body H3.Arrays is | ||||
|  | ||||
| 		return System_Size'First; | ||||
| 	end Find; | ||||
| 	--function Find (Obj: in Elastic_Array; V: In Item_Array; From_Pos: in System_Index; Find_Dir: in Direction := DIRECTION_FORWARD); | ||||
|  | ||||
| 	function Find (Obj: in Elastic_Array; V: In Item_Array; Start_Pos: in System_Index; Find_Dir: in Direction := DIRECTION_FORWARD) return System_Size is | ||||
| 		End_Pos: System_Size; | ||||
| 	begin | ||||
| 		if Get_Length(Obj) > 0 and then V'Length > 0 and then V'Length <= Get_Length(Obj) then | ||||
| 			End_Pos := Get_Last_Index(Obj) - V'Length + 1; | ||||
|  | ||||
| 			if Find_Dir = DIRECTION_FORWARD then | ||||
| 				for i in Start_Pos .. End_Pos loop | ||||
| 					if Obj.Buffer.Slot(i .. i + V'Length - 1) = V then | ||||
| 						return i; | ||||
| 					end if; | ||||
| 				end loop; | ||||
| 			else | ||||
| 				if Start_Pos < End_Pos then | ||||
| 					End_Pos := Start_Pos; | ||||
| 				end if; | ||||
| 				for i in reverse Get_First_Index(Obj) .. End_Pos loop | ||||
| 					if Obj.Buffer.Slot(i .. i + V'Length - 1) = V then | ||||
| 						return i; | ||||
| 					end if; | ||||
| 				end loop; | ||||
| 			end if; | ||||
| 		end if; | ||||
| 		return System_Size'First; | ||||
| 	end Find; | ||||
|  | ||||
| 	function "=" (Obj: in Elastic_Array; Obj2: in Elastic_Array) return Standard.Boolean is | ||||
| 	begin | ||||
|  | ||||
| @ -62,9 +62,8 @@ package H3.Arrays is | ||||
|  | ||||
| 	procedure Delete (Obj: in out Elastic_Array; From_Pos: in System_Index; To_Pos: in System_Size); | ||||
|  | ||||
|  | ||||
| 	function Find (Obj: in Elastic_Array; V: In Item_Type; Start_Pos: in System_Index; Find_Dir: in Direction := DIRECTION_FORWARD) return System_Size; | ||||
| 	--function Find (Obj: in Elastic_Array; V: In Item_Array; Start_Pos: in System_Index; Find_Dir: in Direction := DIRECTION_FORWARD); | ||||
| 	function Find (Obj: in Elastic_Array; V: In Item_Array; Start_Pos: in System_Index; Find_Dir: in Direction := DIRECTION_FORWARD) return System_Size; | ||||
|  | ||||
| 	function "=" (Obj: in Elastic_Array; Obj2: in Elastic_Array) return Standard.Boolean; | ||||
| 	function "=" (Obj: in Elastic_Array; Obj2: in Item_Array) return Standard.Boolean; | ||||
|  | ||||
| @ -16,7 +16,7 @@ use type H3.System_Size; | ||||
|  | ||||
| procedure hello is | ||||
| 	package S is new H3.Strings(Standard.Wide_Character, Wide_Character'Val(0)); | ||||
| 	package S_I is new H3.Arrays(Integer, 1, 16#FF#); | ||||
| 	 | ||||
|  | ||||
| 	--type Global_Pool is new System.Storage_Pools.Root_Storage_Pool with null record; | ||||
| 	P1: aliased System.Pool_Global.Unbounded_No_Reclaim_Pool; | ||||
| @ -423,6 +423,7 @@ begin | ||||
|  | ||||
|  | ||||
| 	declare | ||||
| 	package S_I is new H3.Arrays(Integer, 1, 16#FF#); | ||||
| 		t1: S_I.Elastic_Array; | ||||
| 	begin | ||||
| 		S_I.Append (t1, 20, 5); | ||||
| @ -438,6 +439,13 @@ begin | ||||
| 		Ada.Text_IO.Put_Line (t1.Find(30, t1.Get_Last_Index, S_I.DIRECTION_BACKWARD)'Img); | ||||
| 		Ada.Text_IO.Put_Line (t1.Find(30, t1.Get_First_Index)'Img); | ||||
| 		Ada.Text_IO.Put_Line (t1.Find(90, t1.Get_First_Index)'Img); | ||||
| 		Ada.Text_IO.Put_Line (t1.Find(90, t1.Get_First_Index)'Img); | ||||
|  | ||||
| 		Ada.Text_IO.Put_Line (t1.Find((30, 30, 30, 30), t1.Get_First_Index)'Img); | ||||
| 		Ada.Text_IO.Put_Line (t1.Find((20, 20), t1.Get_First_Index, S_I.DIRECTION_FORWARD)'Img); | ||||
| 		Ada.Text_IO.Put_Line (t1.Find((20, 20), t1.Get_Last_Index, S_I.DIRECTION_BACKWARD)'Img); | ||||
| 		Ada.Text_IO.Put_Line (t1.Find((30, 20, 20), t1.Get_First_Index, S_I.DIRECTION_FORWARD)'Img); | ||||
| 		Ada.Text_IO.Put_Line (t1.Find((30, 20, 20), t1.Get_Last_Index, S_I.DIRECTION_BACKWARD)'Img); | ||||
| 	end; | ||||
| end; | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user