summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2017-07-05 22:12:59 +1000
committerJed Barber <jjbarber@y7mail.com>2017-07-05 22:12:59 +1000
commit36a5b38d4602aab2ab8607069282afc7ce0c392b (patch)
tree8907ed02fce539bd6e4ca6e9f27cb46899729195
parent52eb6622ee81c50dd41cfbc8ba53cc210c0e9b1e (diff)
Removed extraneous Candidate_Range type in Bundles.Containers
-rw-r--r--src/bundles-containers.adb2
-rw-r--r--src/bundles-containers.ads8
-rw-r--r--src/election.adb20
-rw-r--r--src/stv.adb6
4 files changed, 14 insertions, 22 deletions
diff --git a/src/bundles-containers.adb b/src/bundles-containers.adb
index a027727..d1b1130 100644
--- a/src/bundles-containers.adb
+++ b/src/bundles-containers.adb
@@ -40,7 +40,7 @@ package body Bundles.Containers is
if Current_Prefs (Given_Prefs.Preference_Range'First) /=
Candidates.No_Candidate
then
- Result (Candidate_Range (Current_Prefs (Given_Prefs.Preference_Range'First))).Reference
+ Result (Current_Prefs (Given_Prefs.Preference_Range'First)).Reference
(1).Papers.Append (Current_Prefs);
end if;
end if;
diff --git a/src/bundles-containers.ads b/src/bundles-containers.ads
index 1982693..8caf263 100644
--- a/src/bundles-containers.ads
+++ b/src/bundles-containers.ads
@@ -6,19 +6,19 @@ with
generic
- type Candidate_Range is range <>;
+ Min_Valid : Candidates.CandidateID;
+ Max_Valid : Candidates.CandidateID;
package Bundles.Containers is
package Bundle_Vectors is new Ada.Containers.Vectors
(Index_Type => Positive,
Element_Type => Bundle);
-
-
subtype Bundle_Vector is Bundle_Vectors.Vector;
- type Bundle_Collection is array (Candidate_Range) of Bundle_Vector;
+ subtype Valid_CandidateID is Candidates.CandidateID range Min_Valid .. Max_Valid;
+ type Bundle_Collection is array (Valid_CandidateID) of Bundle_Vector;
procedure Read_Bundles
diff --git a/src/election.adb b/src/election.adb
index c7de32b..7e825b3 100644
--- a/src/election.adb
+++ b/src/election.adb
@@ -22,12 +22,6 @@ package body Election is
package SU renames Ada.Strings.Unbounded;
- -- These make converting back and forth easier.
- -- Why are they distinct types? Because you can't pass a subtype to a generic.
- subtype CanID is Candidates.CandidateID;
- subtype CID_Range is Bundle_Containers.Candidate_Range;
-
-
-- Candidate, preference data, and other information
@@ -79,11 +73,11 @@ package body Election is
This : Entry_Data;
begin
Entries := Entry_Vectors.Empty_Vector;
- for CID in Bundle_Containers.Candidate_Range loop
+ for CID in Bundle_Containers.Valid_CandidateID loop
Given_Bundles.Count_Both
(Pref_Data (CID).First_Element, Votes, Papers);
This :=
- (ID => CanID (CID),
+ (ID => CID,
Vote_Change => Votes,
Total_Votes => Votes,
Paper_Change => Papers,
@@ -421,7 +415,7 @@ package body Election is
Given_Bundles.Count_Both (New_Bundle, Votes_In, Papers_In);
if Votes_In > 0 then
- Pref_Data (CID_Range (Working_ID)).Append (New_Bundle);
+ Pref_Data (Working_ID).Append (New_Bundle);
declare
Entry_Ref : Entry_Vectors.Reference_Type :=
Entries.Reference (Working_Position);
@@ -463,22 +457,22 @@ package body Election is
This_Transfer := Transfers.First_Element;
- while Pref_Data (CID_Range (This_Transfer.From)).Length > 0 loop
+ while Pref_Data (This_Transfer.From).Length > 0 loop
Redistribute_Papers
(Still_Running => Running_Positions,
Already_Excluded => Not_Considered,
- Transfer_Bundle => Pref_Data (CID_Range (This_Transfer.From)).Reference (1),
+ Transfer_Bundle => Pref_Data (This_Transfer.From).Reference (1),
Transfer => This_Transfer,
Fractional_Loss => Fractional_Loss,
Exhausted_Loss => Exhausted_Loss);
- Pref_Data (CID_Range (This_Transfer.From)).Delete (1);
+ Pref_Data (This_Transfer.From).Delete (1);
Fractional.Paper_Change := Fractional.Paper_Change + Fractional_Loss;
Exhausted.Paper_Change := Exhausted.Paper_Change + Exhausted_Loss;
end loop;
- if Pref_Data (CID_Range (This_Transfer.From)).Length = 0 then
+ if Pref_Data (This_Transfer.From).Length = 0 then
declare
Entry_Ref : Entry_Vectors.Reference_Type :=
Entries.Reference (This_Transfer.Position);
diff --git a/src/stv.adb b/src/stv.adb
index 29b18c9..20b5b29 100644
--- a/src/stv.adb
+++ b/src/stv.adb
@@ -237,9 +237,6 @@ begin
-- Set up and run the election singleton
declare
- subtype Valid_CandidateID is Candidates.CandidateID
- range Candidate_Data.First_Index .. Candidate_Data.Last_Index;
-
package Given_Prefs is new Preferences
(Above_Ballot => Above_Ballot,
Below_Ballot => Below_Ballot);
@@ -248,7 +245,8 @@ begin
(Given_Prefs => Given_Prefs);
package Vote_Bundle_Containers is new Vote_Bundles.Containers
- (Candidate_Range => Valid_CandidateID);
+ (Min_Valid => Candidate_Data.First_Index,
+ Max_Valid => Candidate_Data.Last_Index);
package This_Election is new Election
(Given_Bundles => Vote_Bundles,