10 std::ofstream out(path, std::ios::binary);
if(!out)
throw std::runtime_error(
"cannot open output");
12 out.write(
reinterpret_cast<const char*
>(&magic),
sizeof(magic)); out.write(
reinterpret_cast<const char*
>(&n),
sizeof(n)); out.write(
reinterpret_cast<const char*
>(&m),
sizeof(m));
13 for(
VertexId u=0;u<g.
vertex_count();++u)
for(
auto v:g.
neighbors(u)){ out.write(
reinterpret_cast<const char*
>(&u),
sizeof(u)); out.write(
reinterpret_cast<const char*
>(&v),
sizeof(v)); }
16 std::ifstream in(path,std::ios::binary);
if(!in)
throw std::runtime_error(
"cannot open input");
17 std::uint64_t magic=0,n=0,m=0; in.read(
reinterpret_cast<char*
>(&magic),
sizeof(magic)); in.read(
reinterpret_cast<char*
>(&n),
sizeof(n)); in.read(
reinterpret_cast<char*
>(&m),
sizeof(m));
18 if(magic!=0x564758303031ULL)
throw std::runtime_error(
"invalid VeloGraphX binary graph");
19 DynamicGraph g(n,directed);
UpdateBatch b;
for(std::uint64_t i=0;i<m;++i){
VertexId u,v; in.read(
reinterpret_cast<char*
>(&u),
sizeof(u)); in.read(
reinterpret_cast<char*
>(&v),
sizeof(v));
if(!in)
throw std::runtime_error(
"truncated graph file");
if(directed || u<=v) b.
add(u,v); }
std::size_t edge_count_directed() const noexcept
void apply(const UpdateBatch &batch)
std::vector< VertexId > neighbors(VertexId u) const
std::size_t vertex_count() const noexcept
DynamicGraph load_binary(const std::string &path, bool directed=false)
void save_binary(const DynamicGraph &g, const std::string &path)
void add(VertexId u, VertexId v, std::uint64_t ts=0)