Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: LG abstraction #25

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
4 changes: 3 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
julia 0.4
julia 0.6-
LightGraphs
UnsafeAtomics
2 changes: 2 additions & 0 deletions src/StingerWrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ include("algorithms/parallelbfs.jl")
include("algorithms/kcore.jl")
include("generators/kronecker.jl")

include("lg/lg.jl")

end # module
2 changes: 1 addition & 1 deletion src/algorithms/parallelbfs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions src/fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/generators/kronecker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
54 changes: 54 additions & 0 deletions src/lg/core.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import LightGraphs: AbstractGraph, add_edge!, rem_edge!, add_vertex!, add_vertices!,
rem_vertex!, zero, is_directed
import LightGraphs.SimpleGraphs: SimpleEdge

export StingerLG

type StingerLG{T} <: AbstractGraph
s::Stinger
nv::T
end

StingerLG() = StingerLG(Stinger(), 0)

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::SimpleEdge)
remove_edge!(s.s, 0, e.src, e.dst)
end

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

is_directed(g::StingerLG) = true
is_directed(::Type{StingerLG}) = true
62 changes: 62 additions & 0 deletions src/lg/edges.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
export StingerLGEdge, StingerEdgeIterator

import Base: reverse, ==, convert
import LightGraphs: AbstractEdge, src, dst, reverse

struct StingerLGEdge <: AbstractEdge
src::Int64
dst::Int64
direction::Int64
weight::Int64
timefirst::Int64
timerecent::Int64
end

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

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(
src+1, neighbor+1, direction, rawedge.weight, rawedge.timefirst, rawedge.timerecent
)
end
Loading