Add write_log to LinkedLists

Mon, 18 Nov 2019 11:31:40 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 18 Nov 2019 11:31:40 -0500
changeset 3
ec9084e97e46
parent 2
fc7430da1d7a
child 4
59fd17a3cea0

Add write_log to LinkedLists

Manifest.toml file | annotate | diff | comparison | revisions
Project.toml file | annotate | diff | comparison | revisions
src/AlgTools.jl file | annotate | diff | comparison | revisions
src/LinkedLists.jl file | annotate | diff | comparison | revisions
--- a/Manifest.toml	Mon Nov 18 11:30:30 2019 -0500
+++ b/Manifest.toml	Mon Nov 18 11:31:40 2019 -0500
@@ -1,5 +1,12 @@
 # This file is machine-generated - editing it directly is not advised
 
+[[DelimitedFiles]]
+deps = ["Mmap"]
+uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"
+
+[[Mmap]]
+uuid = "a63ad114-7e13-5084-954f-fe012c677804"
+
 [[Printf]]
 deps = ["Unicode"]
 uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
--- a/Project.toml	Mon Nov 18 11:30:30 2019 -0500
+++ b/Project.toml	Mon Nov 18 11:31:40 2019 -0500
@@ -4,4 +4,5 @@
 version = "0.1.0"
 
 [deps]
+DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
 Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
--- a/src/AlgTools.jl	Mon Nov 18 11:30:30 2019 -0500
+++ b/src/AlgTools.jl	Mon Nov 18 11:31:40 2019 -0500
@@ -1,7 +1,7 @@
 module AlgTools
 
+include("StructTools.jl")
 include("LinkedLists.jl")
-include("StructTools.jl")
 include("Iterate.jl")
 include("Util.jl")
 
--- a/src/LinkedLists.jl	Mon Nov 18 11:30:30 2019 -0500
+++ b/src/LinkedLists.jl	Mon Nov 18 11:31:40 2019 -0500
@@ -1,17 +1,22 @@
 ####################################################################
-# Immutable linked list (different from the mutable lists of
+# Immutable linked lists (different from the mutable lists of
 # https://github.com/ChrisRackauckas/LinkedLists.jl)
 ####################################################################
 
 module LinkedLists
 
+using DelimitedFiles
+
+using ..StructTools
+
 ##############
 # Our exports
 ##############
 
 export LinkedListEntry,
        LinkedList,
-       unfold_linked_list
+       unfold_linked_list,
+       write_log
 
 #############
 # Data types
@@ -49,4 +54,13 @@
     return reverse(res)
 end
 
+# Write out a a “log” of LinkedList of IterableStructs as a delimited file
+function write_log(filename::String, log::LinkedList{T}, comment::String) where T <: IterableStruct
+    open(filename, "w") do io
+        print(io, comment)
+        writedlm(io, [String.(fieldnames(T))])
+        writedlm(io, unfold_linked_list(log))
+    end
 end
+
+end

mercurial