예제 #1
0
 def test_in_memory_sort(self):
     l = list(range(1024))
     random.shuffle(l)
     sorter = ExternalSorter(1024)
     self.assertEqual(sorted(l), list(sorter.sorted(l)))
     self.assertEqual(sorted(l, reverse=True), list(sorter.sorted(l, reverse=True)))
     self.assertEqual(sorted(l, key=lambda x: -x), list(sorter.sorted(l, key=lambda x: -x)))
     self.assertEqual(sorted(l, key=lambda x: -x, reverse=True),
                      list(sorter.sorted(l, key=lambda x: -x, reverse=True)))
예제 #2
0
 def test_in_memory_sort(self):
     l = list(range(1024))
     random.shuffle(l)
     sorter = ExternalSorter(1024)
     self.assertEqual(sorted(l), list(sorter.sorted(l)))
     self.assertEqual(sorted(l, reverse=True),
                      list(sorter.sorted(l, reverse=True)))
     self.assertEqual(sorted(l, key=lambda x: -x),
                      list(sorter.sorted(l, key=lambda x: -x)))
     self.assertEqual(
         sorted(l, key=lambda x: -x, reverse=True),
         list(sorter.sorted(l, key=lambda x: -x, reverse=True)))
예제 #3
0
 def internalPartition(iterator):
     sort = ExternalSorter(memory * 0.9).sorted
     return iter(sort(iterator, key=lambda x: x[0], reverse=False))