Created
November 22, 2016 15:32
-
-
Save jamii/bad4f9ff2a6b8c4536cfad8f1e6a5a6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Graph | |
| using Data | |
| using Query | |
| using BenchmarkTools | |
| using Base.Test | |
| srand(999) | |
| const edge1 = Relation(([1, 2, 3, 3, 4], [2, 3, 1, 4, 2]), 2) | |
| const edge2 = Relation((rand(1:Int64(1E5), Int64(1E6)), rand(1:Int64(1E5), Int64(1E6))), 2) | |
| function f(edge) | |
| @query begin | |
| edge(a,b) | |
| @when a < b | |
| edge(b,c) | |
| @when b < c | |
| edge(c,a) | |
| return (a::Int64, b::Int64, c::Int64) | |
| end | |
| end | |
| function test() | |
| @test f(edge1)[1] == [1, 2] | |
| @test f(edge1)[2] == [2, 3] | |
| @test f(edge1)[3] == [3, 4] | |
| end | |
| function bench() | |
| @show @benchmark f(edge1) | |
| @show @benchmark f(edge2) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment