Git Product home page Git Product logo

gaddag's Introduction

GADDAG data structure in Ruby

A GADDAG is a data structure that allows for fast lookup of words by substring. It is a directed acyclic graph, where each word can be constructed from the root via any of its reversed prefixes. Its main application is move generation in Scrabble. The data structure is explained in more detail in the original research paper.

Gem Version Build Status Dependency Status Code Climate

Installation

The gaddag gem is available via Rubygems. Install the gem by adding it to your Gemfile or by running:

gem install gaddag

Usage

Initializing the GADDAG is simple:

require 'gaddag'
gaddag = GADDAG.new

Adding words is done via the add method. This will expand the graph with paths for all the reversed prefixes of the word. Note that this may take some time when adding a large number of words.

File.readlines('/usr/share/dict/words') do |word|
  gaddag.add(word.strip) if word.strip.length == 10 # => #<Gaddag:0x007fc6c24367b0 ... >
end

In order to find all words that contain a given substring, use the find method:

gaddag.find('elevi') => # ["televiewer", "television", "televisual"]

Examples

License

See LICENSE.txt.

gaddag's People

Contributors

thomasbrus avatar

Stargazers

 avatar Michał Kuklis avatar  avatar

Watchers

 avatar James Cloos avatar

Forkers

nicholasklick

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.