From: Tilman Sauerbeck Date: Sun, 12 Jan 2020 09:28:58 +0000 (+0100) Subject: common: Factor out the SectorHeaderIter::sort() method. X-Git-Url: http://git.code-monkey.de/?a=commitdiff_plain;h=a8836e8e83b9fbcd551eb1882dabac01c03efd3b;p=gps-watch.git common: Factor out the SectorHeaderIter::sort() method. --- diff --git a/src/common/logger.rs b/src/common/logger.rs index c355bb3..022b155 100644 --- a/src/common/logger.rs +++ b/src/common/logger.rs @@ -205,18 +205,7 @@ impl<'a> SectorHeaderIter<'a> { if num_elts_to_sort != 0 { // Sort the used directory entries. - for i in (1..((num_elts_to_sort + 1) / 2) + 1).rev() { - downheap(&mut iter.indices, i - 1, num_elts_to_sort - 1, - iter.sector_header); - } - - for i in (1..num_elts_to_sort).rev() { - let t = iter.indices[0]; - iter.indices[0] = iter.indices[i]; - iter.indices[i] = t; - - downheap(&mut iter.indices, 0, i - 1, iter.sector_header); - } + iter.sort(num_elts_to_sort); } // Now put the indices of the unused directory entries in the array. @@ -255,6 +244,21 @@ impl<'a> SectorHeaderIter<'a> { iter } + + fn sort(&mut self, num_elts_to_sort: usize) { + for i in (1..((num_elts_to_sort + 1) / 2) + 1).rev() { + downheap(&mut self.indices, i - 1, num_elts_to_sort - 1, + self.sector_header); + } + + for i in (1..num_elts_to_sort).rev() { + let t = self.indices[0]; + self.indices[0] = self.indices[i]; + self.indices[i] = t; + + downheap(&mut self.indices, 0, i - 1, self.sector_header); + } + } } impl<'a> Iterator for SectorHeaderIter<'a> {