From 1e6579e70e2548e84c81303237bae7c51f6c3c23 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Radek=20Hu=C5=A1ek?= <husek@iuuk.mff.cuni.cz>
Date: Wed, 3 Jun 2020 10:09:53 +0200
Subject: [PATCH] improve count_cdc

Do not slurp whole input at the beginning and keep
extra data in json.
---
 count_cdc.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/count_cdc.py b/count_cdc.py
index 8ed6121..68b3cb8 100755
--- a/count_cdc.py
+++ b/count_cdc.py
@@ -7,19 +7,22 @@ from graph_tools.misc import count_cdc_naive
 from sage.all import Graph
 from parmap import parmap
 
-def process(g6):
-  g6 = g6.rstrip()
-  G = Graph(g6)
+def process(l):
+  j = json.loads(l)
+  G = Graph(j["graph"])
   ret = count_cdc_naive(G)
-  return json.dumps({
-    "graph": g6,
+
+  j.update({
     "cdc_count": ret[0],
     "n": G.num_verts(),
     "expected_cdc_lowerbound": ret[1],
     "is_ok": (ret[0] >= ret[1])
   })
 
-inp = [ l for l in sys.stdin ]
+  return json.dumps(j)
+
+inp = os.fdopen(sys.stdin.fileno())
+sys.stdin = None
 
 nprocs = int(os.getenv("NPROCS", "0")) or None
 for ret in parmap(process, inp, nprocs=nprocs, in_order=False):
-- 
GitLab