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

searches

v0.0.2

Published

Generalised search algorithms

Downloads

9

Readme

Search Algorithms

This is a repository of JavaScript implementations of the following search algorithms:

The search algorithms are designed to be as generic as possible, and require the following parameters to work (in this order):

  • An object position representing a position in a search state, or a node in a graph
  • A function isGoalPosition which, given a position object, tells us if this position represents the goal state (if no "goal state" exists, this function can just return false and the algorithm will search the whole state space).
  • A funciton getNeighbouringPositions which, given a position object, returns an array of the valid positions (or state spaces) next to the given position.
  • [Optional] a function arePositionsEqual which, given two position objects, tells us if they're equal. If not such function is supplied, the comparator == is used to test equality.

The A-Star Search algorithm takes an extra parameter heuristic which, given a position object, returns a number estimating how far it is from the goal space. Note: It's important that this function never over-estimates the distance to the goal.

Return Values

The search functions return a result object with the following information:

  • success: True or False depending on whether or not the search found the goal state
  • exploredPositions: A list of the positions explored in the search in the order in which they were explored.
  • goalPosition: A position obejct that represents the goal position (Only included if success is true)

Example Usage

An example usage of the search algorithms is included in the test/ directory, where each of the algorithms are used to search a maze for a goal. Consult any of these test functions to see how to use the algorithms.

The general pattern is as follows:

// CommonJS style import
var Searches = require('searches');

var result;
// Depth-First Search
result = Searches.DepthFirst.runSearch(origin, isGoalPosition, getNeighbouringPositions, arePositionsEqual);

// Breadth-First Search
result = Searches.BreadthFirst.runSearch(origin, isGoalPosition, getNeighbouringPositions, arePositionsEqual);

// A* Search
var result = Searches.AStar.runSearch(origin, isGoalPosition, getNeighbouringPositions, heuristic, arePositionsEqual);