[codeface] Re: [PATCH 05/26] Sort line information in FileDict

  • From: Wolfgang Mauerer <wolfgang.mauerer@xxxxxxxxxxxxxxxxx>
  • To: <codeface@xxxxxxxxxxxxx>
  • Date: Thu, 24 Nov 2016 10:51:14 +0100



Am 13/10/2016 um 17:29 schrieb Claus Hunsen:

When rewriting the data structure, it can occur that the lines in the
'line_list' list are not properly sorted. To ensure reliability for the
'bisect_right' call in the 'get_line_info_raw', the list is now sorted
after each insertion.

Signed-off-by: Claus Hunsen <hunsen@xxxxxxxxxxxxxxxxx>
---
 codeface/fileCommit.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/codeface/fileCommit.py b/codeface/fileCommit.py
index c6b530a..8aaf5e0 100644
--- a/codeface/fileCommit.py
+++ b/codeface/fileCommit.py
@@ -78,6 +78,7 @@ class FileDict:
         if line_nr < self.lastItem:
             raise ValueError("can only incrementally add items")
         self.line_list.append(line_nr)
+        self.line_list.sort()  # make sure the lines are properly sorted

can you please document (as in the commit message) why the lines
need to be sorted? "properly" might also cause more confusion
for readers -- what's an improperly sorted list? Partially sorted,
or sorted by some other criterion than sort() applies by default?

Acked-by: Wolfgang Mauerer <wolfgang.mauerer@xxxxxxxxxxxxxxxxx>

Thanks, Wolfgang
         self.line_dict[line_nr] = info
 
     def values(self):


Other related posts: