GithubHelp home page GithubHelp logo

jimphle-data-structure's Introduction

Jimphle-data-structure

Jimdo PHP library extraction of data-structure component.

This comes with a Map and a Vector and a Null implementation of the BaseInterface. Facts:

  • Immutable
  • Throws InvalidPropertyException on none-existing keys
  • Is able convert complete trees of different data structures to json
  • Is sometimes not very efficient. For example the fromArray method uses the Vector::isSequentialList check which copies the complete array in memory

A Vector is a representation of an array with sequential numeric indexes:

$vector = new \Jimphle\DataStructure\Vector(
    array(
        'foo',
        'bar'
    )
);

echo $vector[1];

A Map is a representation of an array with key and value:

$map = new \Jimphle\DataStructure\Map(
    array(
        'foo' => 'bar'
    )
);
echo $map->foo;

$map = new \Jimphle\DataStructure\Map(
    array(
        'foo-1' => 'bar'
    )
);
echo $map['foo-1'];

Convert an object tree to json:

$map = new \Jimphle\DataStructure\Map(
    array(
        'who?' => new \Jimphle\DataStructure\Vector(
            array(
                new Jimphle\DataStructure\Map(
                    array(
                        'foo' => 'bar'
                    )
                )
            )
        )
    )
);
echo $map->toJson();

jimphle-data-structure's People

Contributors

bracki avatar morrisjobke avatar partyschaum avatar schnipseljagd avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jimphle-data-structure's Issues

Inconsistencies between constructors and factory method for Maps

What happens

Given the following array:

$arr = array(
  'foo' => 1,
  'bar' => array(
    'baz' => 'hi',
    'boom' => 'there',
  ),
);

creating a Map using the Map::fromArray function gives the following result:

object(Jimphle\DataStructure\Map)#4208 (1) {
  ["data":protected]=>
  array(2) {
    ["foo"]=>
    int(1)
    ["bar"]=>
    object(Jimphle\DataStructure\Map)#3711 (1) {
      ["data":protected]=>
      array(2) {
        ["baz"]=>
        string(2) "hi"
        ["boom"]=>
        string(5) "there"
      }
    }
  }
}

while when using the constructor the following result:

object(Jimphle\DataStructure\Map)#4208 (1) {
  ["data":protected]=>
  array(2) {
    ["foo"]=>
    int(1)
    ["bar"]=>
    array(2) {
      ["baz"]=>
      string(2) "hi"
      ["boom"]=>
      string(5) "there"
    }
  }
}

That is the factory method recursively creates maps when the input arrays is multi-dimensional while the constructor doesn't.

Question

Is this behaviour wanted? And if yes, what's the logic behind it? I found the difference a bit unexpected, confusing and definitely not explicit.

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.