Giter VIP home page Giter VIP logo

medusa's Introduction

Medusa

Build Status

Immutable and persistent data structures for PHP.

Life would be a lot simpler if we had immutable data structures. Code would be easier to understand, easy to test and free of side-effects. Being immutable is not all, these data structures must be efficient. By making them persistent, collections reuse internal structure to minimize the number of operations needed to represent altered versions of an instance of a collection.

Setup and Configuration

Add the following to your composer.json file

{
    "require": {
        "keyvanakbary/medusa": "*"
    }
}

Update the vendor libraries

curl -s http://getcomposer.org/installer | php
php composer.phar install

Usage

Stack

<?php

include 'vendor/autoload.php';

$s = Medusa\Stack::createEmpty();

$s1 = $s->push(1);
$s2 = $s1->pop();
echo $s1->peek();//1
echo $s2->peek();//Runtime exception

Complexity

operation big-O
push O(1)
peek O(1)
pop O(1)
isEmpty O(1)
reverse O(N)
count O(1)

Queue

<?php
include 'vendor/autoload.php';

$q = Medusa\Queue::createEmpty();

$q1 = $q->enqueue(1);
$q2 = $q1->dequeue();
echo $q1->peek();//1
echo $q2->peek();//Runtime exception

Complexity

operation big-O
isEmpty O(1)
peek O(1)
enqueue O(1)
dequeue O(1) in average, O(N) in some cases
count O(1)

medusa's People

Contributors

keyvanakbary avatar magdkudama avatar

Watchers

Loïc Faugeron avatar James Cloos 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.