Giter Club home page Giter Club logo

graph's Introduction

Fireblade Graph

Build Status license swift version platforms

This is a lightweight, fast and easy to use directed acyclic graph (DAG) implementation in Swift.
It is developed and maintained as part of the Fireblade Game Engine project.

๐Ÿš€ Getting Started

These instructions will get you a copy of the project up and running on your local machine and provide a code example.

๐Ÿ“‹ Prerequisites

๐Ÿ’ป Installing

Fireblade Graph is available for all platforms that support Swift 5 and higher and the Swift Package Manager (SPM).

Extend the following lines in your Package.swift file or use it to create a new project.

// swift-tools-version:5.2

import PackageDescription

let package = Package(
    name: "YourPackageName",
    dependencies: [
    .package(url: "https://github.com/fireblade-engine/graph.git", from: "1.3.0")
    ],
    targets: [
        .target(
            name: "YourTargetName",
            dependencies: ["FirebladeGraph"])
    ]
)

๐Ÿ“ Code Example

The Node is the core element of the package.
It is representing a node in a directed acyclic graph (DAG) and holds a (weak) reference to its parent node and references to its child nodes.

To create a graph create a node and add children.

let rootNode = Node<Void>()

let child1 = Node<Void>()
let child2 = Node<Void>()

rootNode.addChild(child1)
rootNode.addChild(child2)

A DAG implementation starts to shine when you can add functionality or behavior to its nodes.
This is acchieved by subclassing Node and implementing the desired behavior in its .updateFromParent() method as well as setting the node's generic Content constraint.

class StringNode: Node<String> {

	let content: String
	
	func myFunc() { ... } // or functions

    override open func updateFromParent() {
        super.updateFromParent()
    
        // ... and do fancy stuff here ...
    }
}

let node = StringNode("Hello World!")

To traverse through the graph from root to leave nodes call .update() on the root node of the graph.

let rootNode = Node<Void>()

// ... build up your graph here ...

rootNode.update()

๐Ÿท๏ธ Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

โœ๏ธ Authors

See also the list of contributors who participated in this project.

๐Ÿ” License

This project is licensed under the MIT License - see the LICENSE file for details

graph's People

Contributors

ctreffs avatar vyo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.