From c668b069df3c0096591783daea0f9c91bf4c08a8 Mon Sep 17 00:00:00 2001 From: Rohit Varkey Thankachan Date: Wed, 5 Apr 2017 04:37:59 -0400 Subject: [PATCH 01/14] Changes for 0.6 --- REQUIRE | 4 +++- src/algorithms/parallelbfs.jl | 2 +- src/stinger_graph.jl | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/REQUIRE b/REQUIRE index d5d6467..0a6d754 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1 +1,3 @@ -julia 0.4 +julia 0.6- +LightGraphs +UnsafeAtomics diff --git a/src/algorithms/parallelbfs.jl b/src/algorithms/parallelbfs.jl index c652de3..c8e46dd 100644 --- a/src/algorithms/parallelbfs.jl +++ b/src/algorithms/parallelbfs.jl @@ -39,7 +39,7 @@ function getindex{T}(q::ThreadQueue{T}, iter) return q.data[iter] end -abstract BFSAlgorithm +abstract type BFSAlgorithm end type LevelSynchronous <: BFSAlgorithm end function bfskernel( diff --git a/src/stinger_graph.jl b/src/stinger_graph.jl index 0cdd7f6..7d5723f 100644 --- a/src/stinger_graph.jl +++ b/src/stinger_graph.jl @@ -33,6 +33,8 @@ ETA_start, ebpool_start, size_t const stingergraphfields = fieldnames(StingerGraph) +@enum StingerFields max_nv=1 max_neblock=2 max_netypes=3 max_nvtypes=4 num_insertions=5 num_deletions=6 num_insertions_last_batch=7 num_deletions_last_batch=8 batch_time=9 update_time=10 queue_size=11 dropped_batches=12 vertices_start=13 physmap_start=14 etype_names_start=15 vtype_names_start=16 ETA_start=17 ebpool_start=18 size_t=19 +#= """ Generates an Enumeration of all fields in `StingerGraph`. The generated fields are of type `StingerFields`. @@ -46,3 +48,4 @@ macro createfieldenums() end @createfieldenums() +=# From 7f86e29164f14124c677b1794d47c9bce79c5c48 Mon Sep 17 00:00:00 2001 From: Rohit Varkey Thankachan Date: Wed, 5 Apr 2017 04:46:16 -0400 Subject: [PATCH 02/14] LG Abstraction --- src/StingerWrapper.jl | 2 + src/fields.jl | 9 ++++ src/lg/core.jl | 48 ++++++++++++++++++++++ src/lg/edges.jl | 96 +++++++++++++++++++++++++++++++++++++++++++ src/lg/lg.jl | 3 ++ src/lg/state.jl | 21 ++++++++++ 6 files changed, 179 insertions(+) create mode 100644 src/lg/core.jl create mode 100644 src/lg/edges.jl create mode 100644 src/lg/lg.jl create mode 100644 src/lg/state.jl diff --git a/src/StingerWrapper.jl b/src/StingerWrapper.jl index 52ebbb8..c43518c 100644 --- a/src/StingerWrapper.jl +++ b/src/StingerWrapper.jl @@ -13,4 +13,6 @@ include("algorithms/parallelbfs.jl") include("algorithms/kcore.jl") include("generators/kronecker.jl") +include("lg/lg.jl") + end # module diff --git a/src/fields.jl b/src/fields.jl index b2ad2fd..7133968 100644 --- a/src/fields.jl +++ b/src/fields.jl @@ -73,6 +73,11 @@ immutable StingerEdgeBlock cache_pad::Int64 end +immutable StingerEdgeArray + length::Int64 + high::Int64 +end + function edgeparse(edge::StingerEdge) direction = edge.neighbor >> 61 #The first 2 bits denote the direction, 1 - in, 2 - out, 3 - both neighbor = ~(7 << 61) & edge.neighbor @@ -89,3 +94,7 @@ function getvertexedgesoffset(s::Stinger, v::Int64) vertex = stinger_vertex_get(s,v) vertex.edges end + +function ETAptr(s::Stinger, etype::Int64) + ETA_ptr = storageptr(s) + s[ETA_start] + etype * (sizeof(StingerEdgeArray) + NUMEDGEBLOCKS*sizeof(Int64)) +end diff --git a/src/lg/core.jl b/src/lg/core.jl new file mode 100644 index 0000000..57423c2 --- /dev/null +++ b/src/lg/core.jl @@ -0,0 +1,48 @@ +using LightGraphs +import LightGraphs: AbstractGraph + +type StingerLG{T} <: AbstractGraph + s::Stinger + nv::T +end + +function add_edge!(s::StingerLG, e::LightGraphs.SimpleGraphs.SimpleEdge) + insert_edge!(s.s, 0, e.src, e.dst, 0, 0) +end + +function rem_edge!(s::StingerLG, e::LightGraphs.SimpleGraphs.SimpleEdge) + remove_edge!(s.s, 0, e.src, e.dst) +end + +#QUESTION: Should I look at changing the stinger config for these? + +function add_vertex!(s::StingerLG) + if (s.nv + 1 < s.s[max_nv]) + s.nv+=1 + return true + else + return false + end +end + +function add_vertices!(s::StingerLG, n::Integer) + if (s.nv + n < s.s[max_nv]) + s.nv+=n + return true + else + return false + end +end + +function rem_vertex!(s::StingerLG) + if s.nv > 0 + s.nv -= 1 + return true + else + return false + end +end + +function zero(s::StingerLG) + StingerLG(Stinger(), 0) +end diff --git a/src/lg/edges.jl b/src/lg/edges.jl new file mode 100644 index 0000000..c1b6fc1 --- /dev/null +++ b/src/lg/edges.jl @@ -0,0 +1,96 @@ +struct StingerLGEdge <: AbstractEdge + src::Int64 + dst::Int64 + direction::Int64 + weight::Int64 + timefirst::Int64 + timerecent::Int64 +end + +#for i in edges(g) + +struct StingerEdgeIterator + s::Stinger +end + +struct StingerEdgeIteratorState + ebpool_priv_ptr::Ptr{Void} + current_eb_ptr::Ptr{Void} + current_eb::StingerEdgeBlock + current_eb_edge_idx::Int64 + ETA_ptr::Ptr{Void} + current_ETA::StingerEdgeArray + current_ETA_index::Int64 + etype::Int64 + netypes::Int64 +end + +function edges(g::StingerLG) + StingerEdgeIterator(g.s) +end + +function start(iterator::StingerEdgeIterator) + ebpool_priv_ptr = storageptr(iterator.s) + iterator.s[ebpool_start] * (sizeof(UInt8)) + sizeof(UInt64) * 2 + ETA_ptr = ETAptr(iterator.s, 0) + current_ETA = unsafe_load(convert(Ptr{StingerEdgeArray}, ETA_ptr)) + current_eb_ptr = ebpool_priv_ptr + unsafe_load(convert(Ptr{UInt64}, ETA_ptr+sizeof(StingerEdgeArray))) * (sizeof(StingerEdgeBlock) + sizeof(StingerEdge)*NUMEDGEBLOCKS) + current_eb = unsafe_load(convert(Ptr{StingerEdgeBlock}, current_eb_ptr)) + StingerEdgeIteratorState( + ebpool_priv_ptr, + current_eb_ptr, + current_eb, + 1, + ETA_ptr, + current_ETA, + 1, + 0, + iterator.s[max_netypes] + ) +end + +function done(iterator::StingerEdgeIterator, state::StingerEdgeIteratorState) + state.etype == state.netypes +end + +function next(iterator::StingerEdgeIterator, state::StingerEdgeIteratorState) + #Load the current edge + rawedge = unsafe_load( + convert(Ptr{StingerEdge}, state.current_eb_ptr+sizeof(StingerEdgeBlock)), + state.current_eb_edge_idx + ) + parsededge = createedge(rawedge, current_eb.vertexid) + #Now set the state to the next edge + state.current_eb_edge_idx+=1 + #Check if edgeblock completed + if (state.current_eb_edge_idx > state.current_eb.high) + state.current_ETA_index+=1 + #Check if all edgeblocks in the ETA are done + if (state.current_ETA_index > state.current_ETA.high) + state.etype+=1 + if (state.etype == state.netypes) + #Termination condition + return parsededge + end + #Update ETA state + state.current_ETA_index=1 + state.ETA_ptr = ETAptr(iterator.s, state.etype) + state.current_ETA = unsafe_load(convert(Ptr{StingerEdgeArray}, ETA_ptr)) + end + #Update edgeblock state + state.current_eb_edge_idx = 1 + state.current_eb_ptr = state.ebpool_priv_ptr + + unsafe_load( + convert(Ptr{UInt64}, state.ETA_ptr+sizeof(StingerEdgeArray)), + state.current_ETA_index + ) * (sizeof(StingerEdgeBlock) + sizeof(StingerEdge)*NUMEDGEBLOCKS) + state.current_eb = unsafe_load(convert(Ptr{StingerEdgeBlock}, current_eb_ptr)) + end + return parsededge +end + +function createedge(rawedge::StingerEdge, src::Int64) + direction, neighbor = edgeparse(rawedge) + StingerLGEdge( + src+1, neighbor+1, direction, rawedge.weight, rawedge.timefirst, rawedge.timerecent + ) +end diff --git a/src/lg/lg.jl b/src/lg/lg.jl new file mode 100644 index 0000000..6164832 --- /dev/null +++ b/src/lg/lg.jl @@ -0,0 +1,3 @@ +include("core.jl") +include("edges.jl") +include("state.jl") diff --git a/src/lg/state.jl b/src/lg/state.jl new file mode 100644 index 0000000..30642d9 --- /dev/null +++ b/src/lg/state.jl @@ -0,0 +1,21 @@ +function nv(g::StingerLG) + g.nv +end + +#= TODO: How do I find the total number of edges in a Stinger? +# Loop through foralledges? +function ne(g::StingerLG) + +end +=# + +function vertices(g::StingerLG) + #Convert to 0 based on all the interface functions. + 1:g.nv +end + +#= +function edges(g::StingerLG, ) + +end +=# From 0d144191bf0209cb727f0d59ae9e3065096c32da Mon Sep 17 00:00:00 2001 From: Rohit Varkey Thankachan Date: Wed, 5 Apr 2017 04:55:29 -0400 Subject: [PATCH 03/14] Working iterator --- src/lg/edges.jl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/lg/edges.jl b/src/lg/edges.jl index c1b6fc1..0e23e81 100644 --- a/src/lg/edges.jl +++ b/src/lg/edges.jl @@ -1,3 +1,7 @@ +export StingerLGEdge, StingerEdgeIterator + +import Base: start, done, next + struct StingerLGEdge <: AbstractEdge src::Int64 dst::Int64 @@ -13,7 +17,7 @@ struct StingerEdgeIterator s::Stinger end -struct StingerEdgeIteratorState +mutable struct StingerEdgeIteratorState ebpool_priv_ptr::Ptr{Void} current_eb_ptr::Ptr{Void} current_eb::StingerEdgeBlock @@ -58,7 +62,7 @@ function next(iterator::StingerEdgeIterator, state::StingerEdgeIteratorState) convert(Ptr{StingerEdge}, state.current_eb_ptr+sizeof(StingerEdgeBlock)), state.current_eb_edge_idx ) - parsededge = createedge(rawedge, current_eb.vertexid) + parsededge = createedge(rawedge, state.current_eb.vertexid) #Now set the state to the next edge state.current_eb_edge_idx+=1 #Check if edgeblock completed @@ -69,7 +73,7 @@ function next(iterator::StingerEdgeIterator, state::StingerEdgeIteratorState) state.etype+=1 if (state.etype == state.netypes) #Termination condition - return parsededge + return (parsededge, state) end #Update ETA state state.current_ETA_index=1 @@ -83,9 +87,9 @@ function next(iterator::StingerEdgeIterator, state::StingerEdgeIteratorState) convert(Ptr{UInt64}, state.ETA_ptr+sizeof(StingerEdgeArray)), state.current_ETA_index ) * (sizeof(StingerEdgeBlock) + sizeof(StingerEdge)*NUMEDGEBLOCKS) - state.current_eb = unsafe_load(convert(Ptr{StingerEdgeBlock}, current_eb_ptr)) + state.current_eb = unsafe_load(convert(Ptr{StingerEdgeBlock}, state.current_eb_ptr)) end - return parsededge + return (parsededge, state) end function createedge(rawedge::StingerEdge, src::Int64) From 755d1ae2da943b54cd7d406bdae58c8412e420b8 Mon Sep 17 00:00:00 2001 From: Rohit Varkey Thankachan Date: Wed, 5 Apr 2017 05:20:00 -0400 Subject: [PATCH 04/14] Finish up the edge interface --- src/lg/core.jl | 2 ++ src/lg/edges.jl | 41 +++++++++++++++++++++++++++++++++++++++-- src/lg/state.jl | 6 ------ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/lg/core.jl b/src/lg/core.jl index 57423c2..0a32439 100644 --- a/src/lg/core.jl +++ b/src/lg/core.jl @@ -6,6 +6,8 @@ type StingerLG{T} <: AbstractGraph nv::T end +StingerLG() = StingerLG(Stinger(), 0) + function add_edge!(s::StingerLG, e::LightGraphs.SimpleGraphs.SimpleEdge) insert_edge!(s.s, 0, e.src, e.dst, 0, 0) end diff --git a/src/lg/edges.jl b/src/lg/edges.jl index 0e23e81..3709bbd 100644 --- a/src/lg/edges.jl +++ b/src/lg/edges.jl @@ -1,6 +1,6 @@ export StingerLGEdge, StingerEdgeIterator -import Base: start, done, next +import Base: start, done, next, reverse, ==, convert struct StingerLGEdge <: AbstractEdge src::Int64 @@ -11,7 +11,44 @@ struct StingerLGEdge <: AbstractEdge timerecent::Int64 end -#for i in edges(g) +function src(edge::StingerLGEdge) + if edge.direction==1 + return edge.dst + else + return edge.src + end +end + +function dst(edge::StingerLGEdge) + if edge.direction==1 + return edge.src + else + return edge.dst + end +end + +reverse(edge::StingerLGEdge) = StingerLGEdge(edge.dst, edge.src, edge.direction, edge.weight, edge.timefirst, edge.timerecent) + +function ==(e1::StingerLGEdge, e2::StingerLGEdge) + e1.src == e2.src && e1.dst == e2.dst && e1.direction == e2.direction && + e1.weight == e2.weight && e1.timefirst == e2.timefirst && e1.timerecent == e2.timerecent +end + +function convert(::Type{Pair}, edge::StingerLGEdge) + if edge.direction==1 + return Pair(edge.dst, edge.src) + else + return Pair(edge.src, edge.dst) + end +end + +function convert(::Type{Tuple}, edge::StingerLGEdge) + if edge.direction==1 + return (edge.dst, edge.src) + else + return (edge.src, edge.dst) + end +end struct StingerEdgeIterator s::Stinger diff --git a/src/lg/state.jl b/src/lg/state.jl index 30642d9..8ed5d7d 100644 --- a/src/lg/state.jl +++ b/src/lg/state.jl @@ -13,9 +13,3 @@ function vertices(g::StingerLG) #Convert to 0 based on all the interface functions. 1:g.nv end - -#= -function edges(g::StingerLG, ) - -end -=# From 21580366685e96a132966207ed3adae18aba0f00 Mon Sep 17 00:00:00 2001 From: Rohit Varkey Thankachan Date: Thu, 6 Apr 2017 15:25:11 -0400 Subject: [PATCH 05/14] Iterator refactor --- src/lg/edges.jl | 81 +------------------- src/lg/iterators.jl | 178 ++++++++++++++++++++++++++++++++++++++++++++ src/lg/lg.jl | 1 + src/lg/state.jl | 4 + 4 files changed, 184 insertions(+), 80 deletions(-) create mode 100644 src/lg/iterators.jl diff --git a/src/lg/edges.jl b/src/lg/edges.jl index 3709bbd..56e029a 100644 --- a/src/lg/edges.jl +++ b/src/lg/edges.jl @@ -1,6 +1,6 @@ export StingerLGEdge, StingerEdgeIterator -import Base: start, done, next, reverse, ==, convert +import Base: reverse, ==, convert struct StingerLGEdge <: AbstractEdge src::Int64 @@ -50,85 +50,6 @@ function convert(::Type{Tuple}, edge::StingerLGEdge) end end -struct StingerEdgeIterator - s::Stinger -end - -mutable struct StingerEdgeIteratorState - ebpool_priv_ptr::Ptr{Void} - current_eb_ptr::Ptr{Void} - current_eb::StingerEdgeBlock - current_eb_edge_idx::Int64 - ETA_ptr::Ptr{Void} - current_ETA::StingerEdgeArray - current_ETA_index::Int64 - etype::Int64 - netypes::Int64 -end - -function edges(g::StingerLG) - StingerEdgeIterator(g.s) -end - -function start(iterator::StingerEdgeIterator) - ebpool_priv_ptr = storageptr(iterator.s) + iterator.s[ebpool_start] * (sizeof(UInt8)) + sizeof(UInt64) * 2 - ETA_ptr = ETAptr(iterator.s, 0) - current_ETA = unsafe_load(convert(Ptr{StingerEdgeArray}, ETA_ptr)) - current_eb_ptr = ebpool_priv_ptr + unsafe_load(convert(Ptr{UInt64}, ETA_ptr+sizeof(StingerEdgeArray))) * (sizeof(StingerEdgeBlock) + sizeof(StingerEdge)*NUMEDGEBLOCKS) - current_eb = unsafe_load(convert(Ptr{StingerEdgeBlock}, current_eb_ptr)) - StingerEdgeIteratorState( - ebpool_priv_ptr, - current_eb_ptr, - current_eb, - 1, - ETA_ptr, - current_ETA, - 1, - 0, - iterator.s[max_netypes] - ) -end - -function done(iterator::StingerEdgeIterator, state::StingerEdgeIteratorState) - state.etype == state.netypes -end - -function next(iterator::StingerEdgeIterator, state::StingerEdgeIteratorState) - #Load the current edge - rawedge = unsafe_load( - convert(Ptr{StingerEdge}, state.current_eb_ptr+sizeof(StingerEdgeBlock)), - state.current_eb_edge_idx - ) - parsededge = createedge(rawedge, state.current_eb.vertexid) - #Now set the state to the next edge - state.current_eb_edge_idx+=1 - #Check if edgeblock completed - if (state.current_eb_edge_idx > state.current_eb.high) - state.current_ETA_index+=1 - #Check if all edgeblocks in the ETA are done - if (state.current_ETA_index > state.current_ETA.high) - state.etype+=1 - if (state.etype == state.netypes) - #Termination condition - return (parsededge, state) - end - #Update ETA state - state.current_ETA_index=1 - state.ETA_ptr = ETAptr(iterator.s, state.etype) - state.current_ETA = unsafe_load(convert(Ptr{StingerEdgeArray}, ETA_ptr)) - end - #Update edgeblock state - state.current_eb_edge_idx = 1 - state.current_eb_ptr = state.ebpool_priv_ptr + - unsafe_load( - convert(Ptr{UInt64}, state.ETA_ptr+sizeof(StingerEdgeArray)), - state.current_ETA_index - ) * (sizeof(StingerEdgeBlock) + sizeof(StingerEdge)*NUMEDGEBLOCKS) - state.current_eb = unsafe_load(convert(Ptr{StingerEdgeBlock}, state.current_eb_ptr)) - end - return (parsededge, state) -end - function createedge(rawedge::StingerEdge, src::Int64) direction, neighbor = edgeparse(rawedge) StingerLGEdge( diff --git a/src/lg/iterators.jl b/src/lg/iterators.jl new file mode 100644 index 0000000..7c8e8e5 --- /dev/null +++ b/src/lg/iterators.jl @@ -0,0 +1,178 @@ +import Base: start, done, next + +"""To iterator over an EdgeBlock""" +struct EdgeBlockIterator + current_eb_ptr::Ptr{Void} + current_eb::StingerEdgeBlock +end + +struct EdgeBlockIteratorState + current_eb_edge_idx::Int64 + current_edge::StingerLGEdge +end + +"""Iterate till the first non blank edge or until done condition""" +function start(iter::EdgeBlockIterator) + for init_eb_edge_idx=1:iter.current_eb.high + rawedge = unsafe_load( + convert(Ptr{StingerEdge}, iter.current_eb_ptr+sizeof(StingerEdgeBlock)), + init_eb_edge_idx + ) + if rawedge.neighbor >= 0 + #Set state on finding a valid edge + return EdgeBlockIteratorState( + init_eb_edge_idx, + createedge(rawedge, iter.current_eb.vertexid) + ) + end + end + #Return done state if no valid edge found + EdgeBlockIteratorState(iter.current_eb.high+1, StingerLGEdge(0, 0, 0, 0, 0, 0)) +end + +function done(iter::EdgeBlockIterator, state::EdgeBlockIteratorState) + state.current_eb_edge_idx > iter.current_eb.high +end + +"""Loads the edge pointed to by state, updates state when next non-blank edge is found or termination condition is satisfied""" +function next(iter::EdgeBlockIterator, state::EdgeBlockIteratorState) + current_edge = state.current_edge + for edge_idx=state.current_eb_edge_idx+1:iter.current_eb.high + rawedge = unsafe_load( + convert(Ptr{StingerEdge}, iter.current_eb_ptr+sizeof(StingerEdgeBlock)), + edge_idx + ) + if rawedge.neighbor >= 0 + #Set state on finding a valid edge + return ( + current_edge, + EdgeBlockIteratorState( + edge_idx, + createedge(rawedge, iter.current_eb.vertexid) + ) + ) + break + end + end + return ( + current_edge, + EdgeBlockIteratorState(iter.current_eb.high+1, current_edge) + ) +end + +struct StingerEdgeIterator + s::Stinger + ebpool_priv_ptr::Ptr{Void} + netypes::Int64 +end + +function StingerEdgeIterator(s::Stinger) + ebpool_priv_ptr = storageptr(s) + s[ebpool_start] * (sizeof(UInt8)) + sizeof(UInt64) * 2 + netypes = s[max_netypes] + StingerEdgeIterator(s, ebpool_priv_ptr, netypes) +end + +struct StingerEdgeIteratorState + ETA_ptr::Ptr{Void} + current_ETA::StingerEdgeArray + current_ETA_index::Int64 + etype::Int64 + eb_iterator::EdgeBlockIterator + eb_iterator_state::EdgeBlockIteratorState +end + +function start(iter::StingerEdgeIterator) + for etype=0:iter.netypes-1 + ETA_ptr = ETAptr(iter.s, etype) + current_ETA = unsafe_load(convert(Ptr{StingerEdgeArray}, ETA_ptr)) + for current_ETA_index=1:current_ETA.high + current_eb_ptr = iter.ebpool_priv_ptr + + unsafe_load( + convert(Ptr{UInt64}, ETA_ptr+sizeof(StingerEdgeArray)) + ) * + (sizeof(StingerEdgeBlock) + sizeof(StingerEdge)*NUMEDGEBLOCKS) + current_eb = unsafe_load(convert(Ptr{StingerEdgeBlock}, current_eb_ptr)) + + eb_iterator = EdgeBlockIterator(current_eb_ptr, current_eb) + eb_iterator_state = start(eb_iterator) + if(!(done(eb_iterator, eb_iterator_state))) + return StingerEdgeIteratorState( + ETA_ptr, + current_ETA, + current_ETA_index, + etype, + eb_iterator, + eb_iterator_state + ) + end + end + end + StingerEdgeIteratorState( + Ptr{Void}(0), + StingerEdgeArray(0, 0), + 0, + iter.netypes, + EdgeBlockIterator(Ptr{Void}(0), StingerEdgeBlock(0, 0, 0, 0, 0, 0, 0, 0)), + EdgeBlockIteratorState(0, StingerLGEdge(0, 0, 0, 0, 0, 0)) + ) +end + +function done(iter::StingerEdgeIterator, state::StingerEdgeIteratorState) + state.etype == iter.netypes +end + +function next(iter::StingerEdgeIterator, state::StingerEdgeIteratorState) + #Load the current edge + (current_edge, eb_iterator_state) = next(state.eb_iterator, state.eb_iterator_state) + ETA_ptr = state.ETA_ptr + current_ETA = state.current_ETA + current_ETA_index = state.current_ETA_index + etype = state.etype + eb_iterator = state.eb_iterator + #If edgeblock completed + while done(eb_iterator, eb_iterator_state) + current_ETA_index+=1 + if (current_ETA_index > current_ETA.high) + #ETA done, move on to next etype + etype+=1 + if (etype == iter.netypes) + #DONE condition + return ( + current_edge, + StingerEdgeIteratorState( + Ptr{Void}(0), + StingerEdgeArray(0, 0), + 0, + iter.netypes, + EdgeBlockIterator(Ptr{Void}(0), StingerEdgeBlock(0, 0, 0, 0, 0, 0, 0, 0)), + EdgeBlockIteratorState(0, StingerLGEdge(0, 0, 0, 0, 0, 0)) + ) + ) + end + current_ETA_index=1 + ETA_ptr = ETAptr(iter.s, etype) + current_ETA = unsafe_load(convert(Ptr{StingerEdgeArray}, ETA_ptr)) + end + current_eb_ptr = iter.ebpool_priv_ptr + + unsafe_load( + convert(Ptr{UInt64}, ETA_ptr+sizeof(StingerEdgeArray)), + current_ETA_index + ) * + (sizeof(StingerEdgeBlock) + sizeof(StingerEdge)*NUMEDGEBLOCKS) + current_eb = unsafe_load(convert(Ptr{StingerEdgeBlock}, current_eb_ptr)) + eb_iterator = EdgeBlockIterator(current_eb_ptr, current_eb) + eb_iterator_state = start(eb_iterator) + end + + return ( + current_edge, + StingerEdgeIteratorState( + ETA_ptr, + current_ETA, + current_ETA_index, + etype, + eb_iterator, + eb_iterator_state + ) + ) +end diff --git a/src/lg/lg.jl b/src/lg/lg.jl index 6164832..0ce758a 100644 --- a/src/lg/lg.jl +++ b/src/lg/lg.jl @@ -1,3 +1,4 @@ include("core.jl") include("edges.jl") +include("iterators.jl") include("state.jl") diff --git a/src/lg/state.jl b/src/lg/state.jl index 8ed5d7d..126c9e7 100644 --- a/src/lg/state.jl +++ b/src/lg/state.jl @@ -13,3 +13,7 @@ function vertices(g::StingerLG) #Convert to 0 based on all the interface functions. 1:g.nv end + +function edges(g::StingerLG) + StingerEdgeIterator(g.s) +end From db30ab96d704a09c01ac7ca0c201be11c1e253e9 Mon Sep 17 00:00:00 2001 From: Rohit Varkey Thankachan Date: Thu, 6 Apr 2017 17:00:23 -0400 Subject: [PATCH 06/14] Directed edge iterators --- src/lg/iterators.jl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/lg/iterators.jl b/src/lg/iterators.jl index 7c8e8e5..c5077a7 100644 --- a/src/lg/iterators.jl +++ b/src/lg/iterators.jl @@ -176,3 +176,28 @@ function next(iter::StingerEdgeIterator, state::StingerEdgeIteratorState) ) ) end + +struct StingerDirectedEdgesIterator + edgeiter::StingerEdgeIterator + direction::Int64 +end + +function start(iter::StingerDirectedEdgesIterator) + state = start(iter.edgeiter) + while(!done(iter.edgeiter, state) && xor(state.eb_iterator_state.current_edge.direction,iter.direction)==3) + (_, state) = next(iter.edgeiter, state) + end + state +end + +function next(iter::StingerDirectedEdgesIterator, state::StingerEdgeIteratorState) + current_edge, state = next(iter.edgeiter, state) + while(!done(iter.edgeiter, state) && xor(state.eb_iterator_state.current_edge.direction,iter.direction)==3) + edge, state = next(iter.edgeiter, state) + end + (current_edge, state) +end + +function done(iter::StingerDirectedEdgesIterator, state::StingerEdgeIteratorState) + done(iter.edgeiter, state) +end From c71c44db1c0be7a4f5151d2ec0c57ca3c5972c6f Mon Sep 17 00:00:00 2001 From: Rohit Varkey Thankachan Date: Thu, 6 Apr 2017 17:08:26 -0400 Subject: [PATCH 07/14] Abstract type for iterators. --- src/lg/iterators.jl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lg/iterators.jl b/src/lg/iterators.jl index c5077a7..e2e9fea 100644 --- a/src/lg/iterators.jl +++ b/src/lg/iterators.jl @@ -1,7 +1,12 @@ import Base: start, done, next +abstract type AbstractStingerEdgeIterator end + +eltype(::Type{AbstractStingerEdgeIterator}) = StingerLGEdge +iteratorsize(::Type{AbstractStingerEdgeIterator}) = Base.SizeUnknown() + """To iterator over an EdgeBlock""" -struct EdgeBlockIterator +struct EdgeBlockIterator <: AbstractStingerEdgeIterator current_eb_ptr::Ptr{Void} current_eb::StingerEdgeBlock end @@ -60,7 +65,7 @@ function next(iter::EdgeBlockIterator, state::EdgeBlockIteratorState) ) end -struct StingerEdgeIterator +struct StingerEdgeIterator <: AbstractStingerEdgeIterator s::Stinger ebpool_priv_ptr::Ptr{Void} netypes::Int64 @@ -177,7 +182,7 @@ function next(iter::StingerEdgeIterator, state::StingerEdgeIteratorState) ) end -struct StingerDirectedEdgesIterator +struct StingerDirectedEdgesIterator <: AbstractStingerEdgeIterator edgeiter::StingerEdgeIterator direction::Int64 end From 6b7338b324c0b3c352aec2669c9153ccb0999786 Mon Sep 17 00:00:00 2001 From: Rohit Varkey Thankachan Date: Thu, 6 Apr 2017 23:22:12 -0400 Subject: [PATCH 08/14] Vertex Iterators --- src/lg/iterators.jl | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/lg/iterators.jl b/src/lg/iterators.jl index e2e9fea..5c26f58 100644 --- a/src/lg/iterators.jl +++ b/src/lg/iterators.jl @@ -206,3 +206,52 @@ end function done(iter::StingerDirectedEdgesIterator, state::StingerEdgeIteratorState) done(iter.edgeiter, state) end + +struct StingerVertexEdgeIterator <: AbstractStingerEdgeIterator + ebpool_priv_ptr::Ptr{Void} + vertex::StingerVertex +end + +function StingerVertexEdgeIterator(s::Stinger, src::Int64) + ebpool_priv_ptr = storageptr(s) + s[ebpool_start] * (sizeof(UInt8)) + sizeof(UInt64) * 2 + vertex = getvertex(s, src) + StingerVertexEdgeIterator( + ebpool_priv_ptr, + vertex + ) +end + +struct StingerVertexEdgeIteratorState + eb_iter::EdgeBlockIterator + eb_state::EdgeBlockIteratorState +end + +function start(iter::StingerVertexEdgeIterator) + current_eb_ptr = iter.ebpool_priv_ptr + iter.vertex.edges * (sizeof(StingerEdgeBlock) + sizeof(StingerEdge)*NUMEDGEBLOCKS) + current_eb = unsafe_load(convert(Ptr{StingerEdgeBlock}, current_eb_ptr)) + eb_iter = EdgeBlockIterator(current_eb_ptr, current_eb) + eb_state = start(eb_iter) + while (iter.ebpool_priv_ptr != eb_iter.current_eb_ptr && done(eb_iter, eb_state)) + current_eb_ptr = iter.ebpool_priv_ptr + eb_iter.current_eb.next * (sizeof(StingerEdgeBlock) + sizeof(StingerEdge)*NUMEDGEBLOCKS) + current_eb = unsafe_load(convert(Ptr{StingerEdgeBlock}, current_eb_ptr)) + eb_iter = EdgeBlockIterator(current_eb_ptr, current_eb) + eb_state = start(eb_iter) + end + StingerVertexEdgeIteratorState(eb_iter, eb_state) +end + +function done(iter::StingerVertexEdgeIterator, state::StingerVertexEdgeIteratorState) + iter.ebpool_priv_ptr == state.eb_iter.current_eb_ptr +end + +function next(iter::StingerVertexEdgeIterator, state::StingerVertexEdgeIteratorState) + current_edge, eb_state = next(state.eb_iter, state.eb_state) + eb_iter = state.eb_iter + while (iter.ebpool_priv_ptr != eb_iter.current_eb_ptr && done(eb_iter, eb_state)) + current_eb_ptr = iter.ebpool_priv_ptr + eb_iter.current_eb.next * (sizeof(StingerEdgeBlock) + sizeof(StingerEdge)*NUMEDGEBLOCKS) + current_eb = unsafe_load(convert(Ptr{StingerEdgeBlock}, current_eb_ptr)) + eb_iter = EdgeBlockIterator(current_eb_ptr, current_eb) + eb_state = start(eb_iter) + end + (current_edge, StingerVertexEdgeIteratorState(eb_iter, eb_state)) +end From 07f1c72816126f1ca6108857f6b1babdc4ed2e3b Mon Sep 17 00:00:00 2001 From: Rohit Varkey Thankachan Date: Tue, 11 Apr 2017 13:38:39 -0400 Subject: [PATCH 09/14] Move up direction check into edgeblocks --- src/lg/iterators.jl | 73 +++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 43 deletions(-) diff --git a/src/lg/iterators.jl b/src/lg/iterators.jl index 5c26f58..688ca02 100644 --- a/src/lg/iterators.jl +++ b/src/lg/iterators.jl @@ -9,6 +9,7 @@ iteratorsize(::Type{AbstractStingerEdgeIterator}) = Base.SizeUnknown() struct EdgeBlockIterator <: AbstractStingerEdgeIterator current_eb_ptr::Ptr{Void} current_eb::StingerEdgeBlock + dir::Int64 end struct EdgeBlockIteratorState @@ -23,7 +24,7 @@ function start(iter::EdgeBlockIterator) convert(Ptr{StingerEdge}, iter.current_eb_ptr+sizeof(StingerEdgeBlock)), init_eb_edge_idx ) - if rawedge.neighbor >= 0 + if rawedge.neighbor >=0 && xor(rawedge.neighbor>>61, iter.dir) != 3 #Set state on finding a valid edge return EdgeBlockIteratorState( init_eb_edge_idx, @@ -47,7 +48,7 @@ function next(iter::EdgeBlockIterator, state::EdgeBlockIteratorState) convert(Ptr{StingerEdge}, iter.current_eb_ptr+sizeof(StingerEdgeBlock)), edge_idx ) - if rawedge.neighbor >= 0 + if rawedge.neighbor >=0 && xor(rawedge.neighbor>>61, iter.dir) != 3 #Set state on finding a valid edge return ( current_edge, @@ -69,12 +70,17 @@ struct StingerEdgeIterator <: AbstractStingerEdgeIterator s::Stinger ebpool_priv_ptr::Ptr{Void} netypes::Int64 + dir::Int64 end -function StingerEdgeIterator(s::Stinger) +function StingerEdgeIterator(s::Stinger, dir::Int64) ebpool_priv_ptr = storageptr(s) + s[ebpool_start] * (sizeof(UInt8)) + sizeof(UInt64) * 2 netypes = s[max_netypes] - StingerEdgeIterator(s, ebpool_priv_ptr, netypes) + StingerEdgeIterator(s, ebpool_priv_ptr, netypes, dir) +end + +function StingerEdgeIterator(s::Stinger) + StingerEdgeIterator(s, 3) end struct StingerEdgeIteratorState @@ -93,12 +99,13 @@ function start(iter::StingerEdgeIterator) for current_ETA_index=1:current_ETA.high current_eb_ptr = iter.ebpool_priv_ptr + unsafe_load( - convert(Ptr{UInt64}, ETA_ptr+sizeof(StingerEdgeArray)) - ) * - (sizeof(StingerEdgeBlock) + sizeof(StingerEdge)*NUMEDGEBLOCKS) + convert(Ptr{UInt64}, ETA_ptr+sizeof(StingerEdgeArray)), + current_ETA_index + ) * + (sizeof(StingerEdgeBlock) + sizeof(StingerEdge)*NUMEDGEBLOCKS) current_eb = unsafe_load(convert(Ptr{StingerEdgeBlock}, current_eb_ptr)) - eb_iterator = EdgeBlockIterator(current_eb_ptr, current_eb) + eb_iterator = EdgeBlockIterator(current_eb_ptr, current_eb, iter.dir) eb_iterator_state = start(eb_iterator) if(!(done(eb_iterator, eb_iterator_state))) return StingerEdgeIteratorState( @@ -117,7 +124,7 @@ function start(iter::StingerEdgeIterator) StingerEdgeArray(0, 0), 0, iter.netypes, - EdgeBlockIterator(Ptr{Void}(0), StingerEdgeBlock(0, 0, 0, 0, 0, 0, 0, 0)), + EdgeBlockIterator(Ptr{Void}(0), StingerEdgeBlock(0, 0, 0, 0, 0, 0, 0, 0), iter.dir), EdgeBlockIteratorState(0, StingerLGEdge(0, 0, 0, 0, 0, 0)) ) end @@ -149,7 +156,7 @@ function next(iter::StingerEdgeIterator, state::StingerEdgeIteratorState) StingerEdgeArray(0, 0), 0, iter.netypes, - EdgeBlockIterator(Ptr{Void}(0), StingerEdgeBlock(0, 0, 0, 0, 0, 0, 0, 0)), + EdgeBlockIterator(Ptr{Void}(0), StingerEdgeBlock(0, 0, 0, 0, 0, 0, 0, 0), iter.dir), EdgeBlockIteratorState(0, StingerLGEdge(0, 0, 0, 0, 0, 0)) ) ) @@ -165,7 +172,7 @@ function next(iter::StingerEdgeIterator, state::StingerEdgeIteratorState) ) * (sizeof(StingerEdgeBlock) + sizeof(StingerEdge)*NUMEDGEBLOCKS) current_eb = unsafe_load(convert(Ptr{StingerEdgeBlock}, current_eb_ptr)) - eb_iterator = EdgeBlockIterator(current_eb_ptr, current_eb) + eb_iterator = EdgeBlockIterator(current_eb_ptr, current_eb, iter.dir) eb_iterator_state = start(eb_iterator) end @@ -182,42 +189,22 @@ function next(iter::StingerEdgeIterator, state::StingerEdgeIteratorState) ) end -struct StingerDirectedEdgesIterator <: AbstractStingerEdgeIterator - edgeiter::StingerEdgeIterator - direction::Int64 -end - -function start(iter::StingerDirectedEdgesIterator) - state = start(iter.edgeiter) - while(!done(iter.edgeiter, state) && xor(state.eb_iterator_state.current_edge.direction,iter.direction)==3) - (_, state) = next(iter.edgeiter, state) - end - state -end - -function next(iter::StingerDirectedEdgesIterator, state::StingerEdgeIteratorState) - current_edge, state = next(iter.edgeiter, state) - while(!done(iter.edgeiter, state) && xor(state.eb_iterator_state.current_edge.direction,iter.direction)==3) - edge, state = next(iter.edgeiter, state) - end - (current_edge, state) -end - -function done(iter::StingerDirectedEdgesIterator, state::StingerEdgeIteratorState) - done(iter.edgeiter, state) -end - struct StingerVertexEdgeIterator <: AbstractStingerEdgeIterator ebpool_priv_ptr::Ptr{Void} vertex::StingerVertex + dir::Int64 end function StingerVertexEdgeIterator(s::Stinger, src::Int64) + StingerVertexEdgeIterator(s, src, 3) +end +function StingerVertexEdgeIterator(s::Stinger, src::Int64, dir::Int64) ebpool_priv_ptr = storageptr(s) + s[ebpool_start] * (sizeof(UInt8)) + sizeof(UInt64) * 2 vertex = getvertex(s, src) StingerVertexEdgeIterator( ebpool_priv_ptr, - vertex + vertex, + dir ) end @@ -229,28 +216,28 @@ end function start(iter::StingerVertexEdgeIterator) current_eb_ptr = iter.ebpool_priv_ptr + iter.vertex.edges * (sizeof(StingerEdgeBlock) + sizeof(StingerEdge)*NUMEDGEBLOCKS) current_eb = unsafe_load(convert(Ptr{StingerEdgeBlock}, current_eb_ptr)) - eb_iter = EdgeBlockIterator(current_eb_ptr, current_eb) + eb_iter = EdgeBlockIterator(current_eb_ptr, current_eb, iter.dir) eb_state = start(eb_iter) - while (iter.ebpool_priv_ptr != eb_iter.current_eb_ptr && done(eb_iter, eb_state)) + while (eb_iter.current_eb.next!=0 && done(eb_iter, eb_state)) current_eb_ptr = iter.ebpool_priv_ptr + eb_iter.current_eb.next * (sizeof(StingerEdgeBlock) + sizeof(StingerEdge)*NUMEDGEBLOCKS) current_eb = unsafe_load(convert(Ptr{StingerEdgeBlock}, current_eb_ptr)) - eb_iter = EdgeBlockIterator(current_eb_ptr, current_eb) + eb_iter = EdgeBlockIterator(current_eb_ptr, current_eb, iter.dir) eb_state = start(eb_iter) end StingerVertexEdgeIteratorState(eb_iter, eb_state) end function done(iter::StingerVertexEdgeIterator, state::StingerVertexEdgeIteratorState) - iter.ebpool_priv_ptr == state.eb_iter.current_eb_ptr + state.eb_iter.current_eb.next==0 && done(state.eb_iter, state.eb_state) end function next(iter::StingerVertexEdgeIterator, state::StingerVertexEdgeIteratorState) current_edge, eb_state = next(state.eb_iter, state.eb_state) eb_iter = state.eb_iter - while (iter.ebpool_priv_ptr != eb_iter.current_eb_ptr && done(eb_iter, eb_state)) + while (eb_iter.current_eb.next!=0 && done(eb_iter, eb_state)) current_eb_ptr = iter.ebpool_priv_ptr + eb_iter.current_eb.next * (sizeof(StingerEdgeBlock) + sizeof(StingerEdge)*NUMEDGEBLOCKS) current_eb = unsafe_load(convert(Ptr{StingerEdgeBlock}, current_eb_ptr)) - eb_iter = EdgeBlockIterator(current_eb_ptr, current_eb) + eb_iter = EdgeBlockIterator(current_eb_ptr, current_eb, iter.dir) eb_state = start(eb_iter) end (current_edge, StingerVertexEdgeIteratorState(eb_iter, eb_state)) From 992bc34b1a3fd03694848e22d50a4f2d9a514886 Mon Sep 17 00:00:00 2001 From: Rohit Varkey Thankachan Date: Tue, 11 Apr 2017 13:43:40 -0400 Subject: [PATCH 10/14] ! -> .! --- src/generators/kronecker.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generators/kronecker.jl b/src/generators/kronecker.jl index 77dcfb7..0815ce8 100644 --- a/src/generators/kronecker.jl +++ b/src/generators/kronecker.jl @@ -22,7 +22,7 @@ function kronecker( for ib in 1:scale ii_bit = rand(1, m) .> ab - jj_bit = rand(1, m) .> ( cnorm * ii_bit + anorm * !(ii_bit) ) + jj_bit = rand(1, m) .> ( cnorm * ii_bit + anorm * .!(ii_bit) ) ij = ij .+ 2^(ib-1) .* [ii_bit; jj_bit] end From 701ccc0ad31677e020808224e8483ee31afec013 Mon Sep 17 00:00:00 2001 From: Rohit Varkey Thankachan Date: Tue, 11 Apr 2017 14:43:40 -0400 Subject: [PATCH 11/14] neighbors --- src/lg/core.jl | 2 -- src/lg/state.jl | 29 +++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/lg/core.jl b/src/lg/core.jl index 0a32439..7283d72 100644 --- a/src/lg/core.jl +++ b/src/lg/core.jl @@ -16,8 +16,6 @@ function rem_edge!(s::StingerLG, e::LightGraphs.SimpleGraphs.SimpleEdge) remove_edge!(s.s, 0, e.src, e.dst) end -#QUESTION: Should I look at changing the stinger config for these? - function add_vertex!(s::StingerLG) if (s.nv + 1 < s.s[max_nv]) s.nv+=1 diff --git a/src/lg/state.jl b/src/lg/state.jl index 126c9e7..9744d26 100644 --- a/src/lg/state.jl +++ b/src/lg/state.jl @@ -2,18 +2,35 @@ function nv(g::StingerLG) g.nv end -#= TODO: How do I find the total number of edges in a Stinger? -# Loop through foralledges? function ne(g::StingerLG) - + ne = 0 + for edge in edges(g, 2) + ne+=1 + end + ne end -=# function vertices(g::StingerLG) #Convert to 0 based on all the interface functions. 1:g.nv end -function edges(g::StingerLG) - StingerEdgeIterator(g.s) +function edges(g::StingerLG, dir::Int64=2) + StingerEdgeIterator(g.s, dir) +end + +function neighbors(g::StingerLG, src::Int64, dir::Int64=2) + neighbors = Vector{Int64}() + for edge in StingerVertexEdgeIterator(g.s, src-1, dir) + push!(neighbors, edge.dst) + end + neighbors +end + +function in_neighbors(g::StingerLG, src::Int64) + neighbors(g, src, 1) +end + +function out_neighbors(g::StingerLG, src::Int64) + neighbors(g, src, 2) end From 2bec3097a3136b47b5f81e6fc15e13a76de9a747 Mon Sep 17 00:00:00 2001 From: Rohit Varkey Thankachan Date: Tue, 11 Apr 2017 15:32:54 -0400 Subject: [PATCH 12/14] has_vertex and has_edge --- src/lg/state.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/lg/state.jl b/src/lg/state.jl index 9744d26..841f940 100644 --- a/src/lg/state.jl +++ b/src/lg/state.jl @@ -34,3 +34,20 @@ end function out_neighbors(g::StingerLG, src::Int64) neighbors(g, src, 2) end + +function hasvertex(g::StingerLG, v::Int64) + v <= g.nv +end + +function hasedge(g::StingerLG, e::StingerLGEdge) + for edge in StingerVertexEdgeIterator(g.s, e.src-1, e.direction) + if edge == e + return true + end + end + return false +end + +function hasedge(g::StingerLG, src::Int64, dst::Int64, dir::Int64) + hasedge(g, StingerLGEdge(src, dst, dir, 0, 0, 0)) +end From 72432ff89da7b138ab63cf439d83d602898a25bd Mon Sep 17 00:00:00 2001 From: Rohit Varkey Thankachan Date: Tue, 11 Apr 2017 16:19:54 -0400 Subject: [PATCH 13/14] Import functions from LightGraphs --- src/lg/core.jl | 10 +++++++++- src/lg/edges.jl | 4 ++++ src/lg/state.jl | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lg/core.jl b/src/lg/core.jl index 7283d72..0f395a7 100644 --- a/src/lg/core.jl +++ b/src/lg/core.jl @@ -1,5 +1,9 @@ using LightGraphs -import LightGraphs: AbstractGraph + +import LightGraphs: AbstractGraph, add_edge!, rem_edge!, add_vertex!, add_vertices!, + rem_vertex!, zero, is_directed + +export StingerLG type StingerLG{T} <: AbstractGraph s::Stinger @@ -46,3 +50,7 @@ end function zero(s::StingerLG) StingerLG(Stinger(), 0) end + +is_directed(g::StingerLG) = true +is_directed(::Type{StingerLG}) = true +is_directed(g::Type{StingerLG{T}}) where T = true diff --git a/src/lg/edges.jl b/src/lg/edges.jl index 56e029a..4e95eb3 100644 --- a/src/lg/edges.jl +++ b/src/lg/edges.jl @@ -1,6 +1,7 @@ export StingerLGEdge, StingerEdgeIterator import Base: reverse, ==, convert +import LightGraphs: src, dst, reverse struct StingerLGEdge <: AbstractEdge src::Int64 @@ -50,6 +51,9 @@ function convert(::Type{Tuple}, edge::StingerLGEdge) end end +StingerLGEdge(t::Tuple) = StingerLGEdge(t[1], t[2], 2, 0, 0, 0) +StingerLGEdge(p::Pair) = StingerLGEdge(p.first, p.second, 2, 0, 0, 0) + function createedge(rawedge::StingerEdge, src::Int64) direction, neighbor = edgeparse(rawedge) StingerLGEdge( diff --git a/src/lg/state.jl b/src/lg/state.jl index 841f940..895d055 100644 --- a/src/lg/state.jl +++ b/src/lg/state.jl @@ -1,3 +1,5 @@ +import LightGraphs: nv, ne, vertices, edges, neighbors, in_neighbors, out_neighbors, hasvertex, hasedge + function nv(g::StingerLG) g.nv end From 76e842a617fad1a4bed0e3d30a841371bf310d74 Mon Sep 17 00:00:00 2001 From: Rohit Varkey Thankachan Date: Tue, 18 Apr 2017 21:53:09 -0400 Subject: [PATCH 14/14] Fix more imports --- src/lg/core.jl | 8 +++----- src/lg/edges.jl | 2 +- src/lg/state.jl | 13 ++++++++----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/lg/core.jl b/src/lg/core.jl index 0f395a7..39edd3e 100644 --- a/src/lg/core.jl +++ b/src/lg/core.jl @@ -1,7 +1,6 @@ -using LightGraphs - import LightGraphs: AbstractGraph, add_edge!, rem_edge!, add_vertex!, add_vertices!, rem_vertex!, zero, is_directed +import LightGraphs.SimpleGraphs: SimpleEdge export StingerLG @@ -12,11 +11,11 @@ end StingerLG() = StingerLG(Stinger(), 0) -function add_edge!(s::StingerLG, e::LightGraphs.SimpleGraphs.SimpleEdge) +function add_edge!(s::StingerLG, e::SimpleEdge) insert_edge!(s.s, 0, e.src, e.dst, 0, 0) end -function rem_edge!(s::StingerLG, e::LightGraphs.SimpleGraphs.SimpleEdge) +function rem_edge!(s::StingerLG, e::SimpleEdge) remove_edge!(s.s, 0, e.src, e.dst) end @@ -53,4 +52,3 @@ end is_directed(g::StingerLG) = true is_directed(::Type{StingerLG}) = true -is_directed(g::Type{StingerLG{T}}) where T = true diff --git a/src/lg/edges.jl b/src/lg/edges.jl index 4e95eb3..b93636a 100644 --- a/src/lg/edges.jl +++ b/src/lg/edges.jl @@ -1,7 +1,7 @@ export StingerLGEdge, StingerEdgeIterator import Base: reverse, ==, convert -import LightGraphs: src, dst, reverse +import LightGraphs: AbstractEdge, src, dst, reverse struct StingerLGEdge <: AbstractEdge src::Int64 diff --git a/src/lg/state.jl b/src/lg/state.jl index 895d055..4c79f6d 100644 --- a/src/lg/state.jl +++ b/src/lg/state.jl @@ -1,4 +1,5 @@ -import LightGraphs: nv, ne, vertices, edges, neighbors, in_neighbors, out_neighbors, hasvertex, hasedge +import LightGraphs: nv, ne, vertices, edges, neighbors, in_neighbors, out_neighbors, + has_vertex, has_edge, has_self_loops function nv(g::StingerLG) g.nv @@ -37,11 +38,11 @@ function out_neighbors(g::StingerLG, src::Int64) neighbors(g, src, 2) end -function hasvertex(g::StingerLG, v::Int64) +function has_vertex(g::StingerLG, v::Int64) v <= g.nv end -function hasedge(g::StingerLG, e::StingerLGEdge) +function has_edge(g::StingerLG, e::StingerLGEdge) for edge in StingerVertexEdgeIterator(g.s, e.src-1, e.direction) if edge == e return true @@ -50,6 +51,8 @@ function hasedge(g::StingerLG, e::StingerLGEdge) return false end -function hasedge(g::StingerLG, src::Int64, dst::Int64, dir::Int64) - hasedge(g, StingerLGEdge(src, dst, dir, 0, 0, 0)) +function has_edge(g::StingerLG, src::Int64, dst::Int64, dir::Int64) + has_edge(g, StingerLGEdge(src, dst, dir, 0, 0, 0)) end + +has_self_loops(g::StingerLG) = false