npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

giraph

v1.0.5

Published

Immutable graph data structures

Downloads

8

Readme

Giraph

Immutable graph data structures

Giraph

Install

npm install -S giraph
bower install -S giraph

Usage

require('giraph')()
  .add('a', { my: 'data' })
  .add('b')
  .add('c')
  .connect('a', 'b', 3)
  .connect('a', 'c')

Docs

Giraph comes with a number of different graph types:

Undirected Graph

Exported as a factory function on the root namespace:

.([options])

Options and defaults

{
  immutable: true
}
require('giraph')() // => empty graph

The undirected graph has the following members

Property: .map: {}

Hashes vertices by id.

Property: .options

Instance options

Property: .length

The number of vertices

.add( id[, data] )

Returns a new instance with Vertex(id[, data]) added to it.

.get( id )

Gets the Vertex at id.

.remove( id )

Returns a new instance with id removed.

.connect( a, b, edgeWeight )

Returns a new instance with a and b connected.

.contains( String|Vertex id )

Returns a boolean indicating whether or not id is in the graph.

Note: if passing in a String, is equivalent to checking id in graph.map.

.merge( a[, b[, ...]] )

Returns a new instance with all other graphs merged into the current.

Note: merging takes Left-to-right precedence. If a and b both contain the same node, c, but have different data attached, b will take precedence.

.each( Function iterator )

Iterates through each vertex. The iterator argument has the following signature:

function( Vertex v, Number i, Graph g )

Returns this

.reduce( Function iterator, Mixed initialValue )

Iterates through the graph, producing a single value. iterator has the following signature

function( Mixed currentValue, Vertex V, Number i, Graph g )

Returns Value of reduction

.instance()

Returns this instance or a clone() depending on options.immutable.

.edges([id])

Returns an array of edges with the following structure:

{ vertices: ['a', 'b'], weight: 10 }

Optionally, pass a vertex ID to only get edges touching that vertex.

.clone()

Returns a new instance of the graph

.weight()

Returns The total weight of all edges in the graph

.mutate(handler)

Allows mutation to occur on an immutable graph for a single turn of the event loop.

Returns the original instance

require('giraph')()
  .mutate(function( g ){
    // Batch operations here
    g.add('a').add('b').add('c');
  })

.mst()

Returns a Minimum Spanning Tree represented as a Graph.

Directed Graph

TODO

Directed Acyclic Graph

TODO

Vertex

A vertex is essentially an Identifier with data attached and connections to other vertices.

It's available under .vertex( id[, data[, options]]).

.id String

ID of the vertex

.data Mixed

Optional attached data

.options Object

Optional options:

{
  immutable: true
}

.clone()

Returns a new instance of the vertex

TODO