Advertisement
adamkowalski

Untitled

Dec 4th, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. pub fn Graph(comptime T: type) type {
  2. return struct {
  3. constants: std.ArrayList(T),
  4.  
  5. pub fn init(allocator: *std.mem.Allocator) Graph(T) {
  6. return .{ .constants = std.ArrayList(T).init(allocator) };
  7. }
  8. };
  9. }
  10.  
  11. pub fn constant(comptime T: type, graph: *Graph(T), value: T) !void {
  12. try graph.constants.append(value);
  13. }
  14.  
  15. test "create graph" {
  16. var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
  17. defer arena.deinit();
  18. const allocator = &arena.allocator;
  19.  
  20. var graph = Graph(i32).init(allocator);
  21. const x = try constant(i32, &graph, 5);
  22. const y = try constant(i32, &graph, 10);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement