summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/candidates-containers.adb15
-rw-r--r--src/candidates-containers.ads23
-rw-r--r--src/election.adb4
-rw-r--r--src/election.ads2
-rw-r--r--src/stv.adb6
5 files changed, 28 insertions, 22 deletions
diff --git a/src/candidates-containers.adb b/src/candidates-containers.adb
index 9dc7f74..b9b56c7 100644
--- a/src/candidates-containers.adb
+++ b/src/candidates-containers.adb
@@ -13,7 +13,7 @@ package body Candidates.Containers is
procedure Read_Candidates
(Filename : in String;
State : in State_Name;
- Candidate_Data : out Candidate_Map)
+ Candidate_Data : out Candidate_Vector)
is
package My_CSV is new CSV;
use Ada.Text_IO;
@@ -22,11 +22,9 @@ package body Candidates.Containers is
Input_File : File_Type;
Current_Record : My_CSV.CSV_Record;
Current_Candidate : Candidate;
-
- Next_ID : CandidateID := CandidateID'First;
begin
Open (Input_File, In_File, Filename);
- Candidate_Data := Candidate_Maps.Empty_Map;
+ Candidate_Data := Candidate_Vectors.Empty_Vector;
while not End_Of_File (Input_File) loop
Current_Record := My_CSV.Parse_Line (Get_Line (Input_File));
@@ -43,8 +41,7 @@ package body Candidates.Containers is
Group => Current_Record.Element (5),
Group_Rank => Current_Record.Element (6),
Party => Current_Record.Element (9));
- Candidate_Data.Insert (Next_ID, Current_Candidate);
- Next_ID := Next_ID + 1;
+ Candidate_Data.Append (Current_Candidate);
end if;
end loop;
@@ -161,7 +158,7 @@ package body Candidates.Containers is
procedure Generate_Ballots
- (Candidate_Data : in Candidate_Map;
+ (Candidate_Data : in Candidate_Vector;
Above_Ballot : out Above_Line_Ballot;
Below_Ballot : out Below_Line_Ballot)
is
@@ -173,9 +170,9 @@ package body Candidates.Containers is
My_Candidate_Data := Cand_Sort_Data_Vectors.Empty_Vector;
for Cursor in Candidate_Data.Iterate loop
- Working_Candidate := Candidate_Maps.Element (Cursor);
+ Working_Candidate := Candidate_Vectors.Element (Cursor);
My_Candidate_Data.Append
- ((Cand_ID => Candidate_Maps.Key (Cursor),
+ ((Cand_ID => Candidate_Vectors.To_Index (Cursor),
Group => Working_Candidate.Group,
Group_Rank => Working_Candidate.Group_Rank));
end loop;
diff --git a/src/candidates-containers.ads b/src/candidates-containers.ads
index 3d9d3f9..b83093a 100644
--- a/src/candidates-containers.ads
+++ b/src/candidates-containers.ads
@@ -2,6 +2,7 @@
with
+ Ada.Containers.Vectors,
Ada.Containers.Ordered_Maps,
Ada.Containers.Ordered_Sets;
@@ -9,31 +10,37 @@ with
package Candidates.Containers is
- package Candidate_Maps is new Ada.Containers.Ordered_Maps
- (Key_Type => CandidateID,
+ -- By making this a Vector, later generics will be able to
+ -- determine the range of valid CandidateIDs.
+ package Candidate_Vectors is new Ada.Containers.Vectors
+ (Index_Type => CandidateID,
Element_Type => Candidate);
- subtype Candidate_Map is Candidate_Maps.Map;
+ subtype Candidate_Vector is Candidate_Vectors.Vector;
procedure Read_Candidates
(Filename : in String;
State : in State_Name;
- Candidate_Data : out Candidate_Map);
+ Candidate_Data : out Candidate_Vector);
+ -- This must be a Map so that the Index/Key doesn't have to start
+ -- from 1, which is important for the Above_Line_Ballot type.
package CandidateID_Maps is new Ada.Containers.Ordered_Maps
(Key_Type => Positive,
Element_Type => CandidateID);
- use type CandidateID_Maps.Map;
+ -- Technically doesn't have to be a Map, but nonetheless is,
+ -- simply for consistency with CandidateID_Maps.
package CandidateID_Map_Maps is new Ada.Containers.Ordered_Maps
(Key_Type => Positive,
- Element_Type => CandidateID_Maps.Map);
+ Element_Type => CandidateID_Maps.Map,
+ "=" => CandidateID_Maps."=");
-- Possibly put some aspects here to ensure the types are as expected?
@@ -42,7 +49,7 @@ package Candidates.Containers is
procedure Generate_Ballots
- (Candidate_Data : in Candidate_Map;
+ (Candidate_Data : in Candidate_Vector;
Above_Ballot : out Above_Line_Ballot;
Below_Ballot : out Below_Line_Ballot);
@@ -61,6 +68,8 @@ package Candidates.Containers is
+ -- Used for passing the CandidateIDs that have been elected, excluded, etc,
+ -- around to various functions when calculating the election.
package CandidateID_Sets is new Ada.Containers.Ordered_Sets
(Element_Type => CandidateID);
diff --git a/src/election.adb b/src/election.adb
index 6a7892f..80c846a 100644
--- a/src/election.adb
+++ b/src/election.adb
@@ -27,7 +27,7 @@ package body Election is
-- Candidate, preference data, and other information
-- that's actively used by the main STV algorithm.
Pref_Data : Bundle_Containers.Bundle_Map;
- Cand_Data : Candidates.Containers.Candidate_Map;
+ Cand_Data : Candidates.Containers.Candidate_Vector;
Entries : Entry_Vectors.Vector;
Exhausted : Extra_Data;
Fractional : Extra_Data;
@@ -94,7 +94,7 @@ package body Election is
-- This must be called before an election is run.
procedure Setup
- (Candidate_Data : in Candidates.Containers.Candidate_Map;
+ (Candidate_Data : in Candidates.Containers.Candidate_Vector;
Preference_File : in String;
Output_Dir, Main_Logfile : in String;
Number_To_Elect : in Natural;
diff --git a/src/election.ads b/src/election.ads
index 0bed2da..c2f367d 100644
--- a/src/election.ads
+++ b/src/election.ads
@@ -18,7 +18,7 @@ package Election is
procedure Setup
- (Candidate_Data : in Candidates.Containers.Candidate_Map;
+ (Candidate_Data : in Candidates.Containers.Candidate_Vector;
Preference_File : in String;
Output_Dir, Main_Logfile : in String;
Number_To_Elect : in Natural;
diff --git a/src/stv.adb b/src/stv.adb
index c10ec2e..eb132cc 100644
--- a/src/stv.adb
+++ b/src/stv.adb
@@ -63,9 +63,9 @@ procedure STV is
Log_File : File_Type;
- Candidate_Data : Candidates.Containers.Candidate_Map;
- Above_Ballot : Candidates.Containers.Above_Line_Ballot;
- Below_Ballot : Candidates.Containers.Below_Line_Ballot;
+ Candidate_Data : Candidates.Containers.Candidate_Vector;
+ Above_Ballot : Candidates.Containers.Above_Line_Ballot;
+ Below_Ballot : Candidates.Containers.Below_Line_Ballot;
begin