|
12 | 12 | import java.util.Arrays; |
13 | 13 | import java.util.Comparator; |
14 | 14 | import java.util.Map.Entry; |
| 15 | +import java.util.concurrent.atomic.AtomicLong; |
15 | 16 | import java.util.function.Function; |
16 | 17 | import java.util.stream.Collectors; |
17 | 18 | import java.util.stream.IntStream; |
@@ -186,40 +187,56 @@ public void sl(String vertexLabel) { |
186 | 187 | /* Utilities */ |
187 | 188 |
|
188 | 189 | public long[] loadVerticesFromFile(String fileName) { |
| 190 | + AtomicLong lines = new AtomicLong(); |
189 | 191 | try (Stream<String> in = Files.lines(Paths.get(fileName), StandardCharsets.UTF_8)) { |
190 | | - return in.mapToLong(label -> g.vertexLabelToId(label)).filter(id -> id > -1).toArray(); |
| 192 | + long[] res = in.mapToLong( |
| 193 | + label -> { |
| 194 | + lines.incrementAndGet(); |
| 195 | + long id = g.vertexLabelToId(label); |
| 196 | + if (id == -1) { |
| 197 | + LOG.debug("Vertex `{}` not found in graph.", label); |
| 198 | + } |
| 199 | + return id; |
| 200 | + }).filter(id -> id > -1).toArray(); |
| 201 | + LOG.info("Loaded {} vertices of {} lines in {}.", res.length, lines, fileName); |
| 202 | + return res; |
191 | 203 | } catch (IOException e) { |
192 | 204 | LOG.error("Failed to load vertices from file {}", fileName, e); |
193 | 205 | } |
194 | 206 | return new long[0]; |
195 | 207 | } |
196 | 208 |
|
197 | 209 | public void saveVerticesToFile(long[] vertexIDs, String fileName) { |
198 | | - try (PrintStream out = new PrintStream(Files.newOutputStream(Paths.get(fileName)), false, |
199 | | - StandardCharsets.UTF_8)) { |
200 | | - Arrays.stream(vertexIDs).forEach(id -> out.println(g.vertexIdToLabel(id))); |
201 | | - } catch (IOException e) { |
202 | | - LOG.error("Failed to write vertices to file {}", fileName, e); |
203 | | - } |
| 210 | + saveVerticesToFile(Arrays.stream(vertexIDs), fileName); |
204 | 211 | } |
205 | 212 |
|
206 | 213 | public void saveVerticesToFile(int[] vertexIDs, String fileName) { |
207 | 214 | saveVerticesToFile(Arrays.stream(vertexIDs), fileName); |
208 | 215 | } |
209 | 216 |
|
210 | 217 | public void saveVerticesToFile(IntStream vertexIDs, String fileName) { |
| 218 | + AtomicLong count = new AtomicLong(); |
211 | 219 | try (PrintStream out = new PrintStream(Files.newOutputStream(Paths.get(fileName)), false, |
212 | 220 | StandardCharsets.UTF_8)) { |
213 | | - vertexIDs.forEach(id -> out.println(g.vertexIdToLabel(id))); |
| 221 | + vertexIDs.forEach(id -> { |
| 222 | + count.incrementAndGet(); |
| 223 | + out.println(g.vertexIdToLabel(id)); |
| 224 | + }); |
| 225 | + LOG.info("Saved {} vertices to file {}.", count.get(), fileName); |
214 | 226 | } catch (IOException e) { |
215 | 227 | LOG.error("Failed to write vertices to file {}", fileName, e); |
216 | 228 | } |
217 | 229 | } |
218 | 230 |
|
219 | 231 | public void saveVerticesToFile(LongStream vertexIDs, String fileName) { |
| 232 | + AtomicLong count = new AtomicLong(); |
220 | 233 | try (PrintStream out = new PrintStream(Files.newOutputStream(Paths.get(fileName)), false, |
221 | 234 | StandardCharsets.UTF_8)) { |
222 | | - vertexIDs.forEach(id -> out.println(g.vertexIdToLabel(id))); |
| 235 | + vertexIDs.forEach(id -> { |
| 236 | + count.incrementAndGet(); |
| 237 | + out.println(g.vertexIdToLabel(id)); |
| 238 | + }); |
| 239 | + LOG.info("Saved {} vertices to file {}.", count.get(), fileName); |
223 | 240 | } catch (IOException e) { |
224 | 241 | LOG.error("Failed to write vertices to file {}", fileName, e); |
225 | 242 | } |
|
0 commit comments