Coder Social home page Coder Social logo

hxorderedmap's Introduction

hxOrderedMap

Ordered maps for haxe 4.0.0-preview5+.

Overview

This is a multi-type abstract that wraps haxe.ds.Map and can be used with the same API.

It also adds a few methods/props (so far length, keysCopy(), clear()).

The main difference with Map is that the order of insertion is preserved.

Minimal example

var keys = ["1", "apple", "banana", "orange", "one", "two", "three"];
var values = [for (i in 0...keys.length) i];

var omap = new OrderedMap();
var map = new Map();

for (i in 0...keys.length) {
  var k = keys[i];
  var v = values[i];

  omap[k] = v;
  map[k] = v;
}

trace("ORDERED  : " + omap); // always  [1 => 0, apple => 1, banana => 2, orange => 3, one => 4, two => 5, three => 6]
trace("UNORDERED: " + map);  // may be  {orange => 3, three => 6, apple => 1, banana => 2, one => 4, 1 => 0, two => 5}

Notes

Internal book-keeping to maintain the order of insertion makes using this data structure a bit slower than using a Map directly (e.g. approximately 1.5-2x slower for set/remove).

Retrieving some info from an OrderedMap instance is faster for the same reason (e.g. getting the number of key-values, a copy of the keys, clearing the map, etc.).

Benchmarks for latest build (https://azrafe7.github.io/haxe-bencharts/?repo=azrafe7/hxOrderedMap).

Note that this is not intended as a replacement for haxe.ds.Map (especially if you care about speed), but I've found it useful in many situations.

License (MIT)

See LICENSE.

hxorderedmap's People

Contributors

azrafe7 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

hxorderedmap's Issues

[cpp] Extending IMap interface doesn't work as I would expect

UPDATE(02 nov 2018): I have a work-around in place that makes the lib work on cpp too. Still not totally happy with it and trying to reduce the case so I can submit a proper issue upstream.

ORIGINAL POST(31 oct 2018):
This most probably is my bad somewhere, although I haven't found a way to solve it yet.
Other targets are ok with it.

Currently I'm just including the IMap interface into the IOrderedMap one (for cpp).

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.