From e518bb656a9f13362d7d6ae1179dc241f4a3587d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20V=C3=A4th?= Date: Tue, 14 Mar 2017 18:08:32 +0100 Subject: [PATCH] Make class SackSet more readable --- knapsack/knapsack.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/knapsack/knapsack.h b/knapsack/knapsack.h index 0f0fba3..eaa276a 100644 --- a/knapsack/knapsack.h +++ b/knapsack/knapsack.h @@ -103,12 +103,13 @@ template WeightSet; - typedef typename std::vector WeightList; + typedef typename KnapsackWeight::WeightList WeightList; typedef typename KnapsackWeight::size_type size_type; + typedef typename KnapsackWeight::weight_type weight_type; private: typedef typename WeightSet::iterator iterator; @@ -134,6 +135,7 @@ template (old_weight - subtract)); + it = set_.insert(static_cast(old_weight - subtract)); } - void DecreaseTo(size_type index, Weight new_weight) { + void DecreaseTo(size_type index, weight_type new_weight) { iterator& it = iterator_[index]; set_.erase(it); - it = set_.insert(static_cast(new_weight)); + it = set_.insert(static_cast(new_weight)); } - // A separate function for possibly optimizing if multiset + // A separate function for possibly optimizing if multiset // should one day obtain separate increase/decrease optimizations - void IncreaseTo(size_type index, Weight new_weight) { + void IncreaseTo(size_type index, weight_type new_weight) { DecreaseTo(index, new_weight); } };