From 52eb6622ee81c50dd41cfbc8ba53cc210c0e9b1e Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Wed, 5 Jul 2017 21:52:49 +1000 Subject: Simplified Bundle_Containers to use an array instead of a Map --- src/bundles-containers.adb | 47 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 35 deletions(-) (limited to 'src/bundles-containers.adb') diff --git a/src/bundles-containers.adb b/src/bundles-containers.adb index a3e2ef0..a027727 100644 --- a/src/bundles-containers.adb +++ b/src/bundles-containers.adb @@ -15,53 +15,23 @@ package body Bundles.Containers is - procedure Add_To_Map - (BMap : in out Bundle_Maps.Map; - Item : in Given_Prefs.Preference_Array) - is - use type Bundle_Maps.Cursor; - use type Bundle_Vectors.Vector; - - Place : Candidates.CandidateID := Item (Given_Prefs.Preference_Range'First); - Current_Cursor : Bundle_Maps.Cursor := BMap.Find (Place); - begin - if Current_Cursor /= Bundle_Maps.No_Element then - declare - Vec_Ref : Bundle_Maps.Reference_Type := - BMap.Reference (Current_Cursor); - Bundle_Ref : Bundle_Vectors.Reference_Type := - Vec_Ref.Reference (Vec_Ref.First_Index); - begin - Bundle_Ref.Papers.Append (Item); - end; - else - declare - New_Bundle : Bundle := Empty_Bundle; - begin - New_Bundle.Papers.Append (Item); - BMap.Insert (Place, Bundle_Vectors.Empty_Vector & New_Bundle); - end; - end if; - end Add_To_Map; - - - - procedure Read_Bundles (Filename : in String; - Result : out Bundle_Maps.Map) + Result : out Bundle_Collection) is package My_CSV is new CSV; use Ada.Text_IO; use type Candidates.CandidateID; + use type Bundle_Vectors.Vector; Input_File : File_Type; Current_Record : My_CSV.CSV_Record; Current_Prefs : Given_Prefs.Preference_Array; begin + Result := (others => Bundle_Vectors.Empty_Vector & Empty_Bundle); + Open (Input_File, In_File, Filename); - Result := Bundle_Maps.Empty_Map; while not End_Of_File (Input_File) loop Current_Record := My_CSV.Parse_Line (Get_Line (Input_File)); if Integer (Current_Record.Length) > 0 then @@ -70,12 +40,19 @@ package body Bundles.Containers is if Current_Prefs (Given_Prefs.Preference_Range'First) /= Candidates.No_Candidate then - Add_To_Map (Result, Current_Prefs); + Result (Candidate_Range (Current_Prefs (Given_Prefs.Preference_Range'First))).Reference + (1).Papers.Append (Current_Prefs); end if; end if; end loop; Close (Input_File); + + for B of Result loop + if B.Reference (1) = Empty_Bundle then + B.Delete (1); + end if; + end loop; end Read_Bundles; -- cgit