Socket
Book a DemoInstallSign in
Socket

simple-graph

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-graph

1.0.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

simple-graph Build Status

A simple, no-frills graph implementation.

Installation

gem install simple-graph

Usage

require 'simple-graph'

Adding Vertices

Let's model an airline that flies to certain cities:

graph = SimpleGraph::Graph.new
graph.add_vertex('Seattle')
graph.add_vertex('Los Angeles')
graph.add_vertex('Denver')
graph.add_vertex('New York')
graph.add_vertex('Miami')

Adding Edges

graph.add_edge('Seattle', 'Los Angeles')
graph.add_edge('Seattle', 'Denver')
graph.add_edge('Los Angeles', 'Miami')
graph.add_edge('Denver', 'New York')
graph.add_edge('New York', 'Miami')

Shortest Path

SimpleGraph doesn't support weighted edges, so let's pretend all these cities are equidistant from each other. We could also say we're trying to find the least number of layovers:

graph.shortest_path('Seattle', 'Miami')  # ["Seattle", "Los Angeles", "Miami"]

Requirements

None.

Running Tests

bundle exec rspec

Authors

FAQs

Package last updated on 23 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.