Giter VIP home page Giter VIP logo

haxesharp's People

Contributors

bsinky avatar nightblade9 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

haxesharp's Issues

Contributing

Are you open to contributions at this point?

I see that the repo is very active, which is awesome! But, it could also mean that it's young enough that you're not currently accepting contributions, which would also be understandable.

As someone who uses C# professional, but is very interested in Haxe for personal projects, this project is very interesting to me!

Please let me know your thoughts on contributions to this project currently, for those who might be interested in getting involved (like me). Thank you.

Dictionary throws with KeyNotFoundException with multiple, similar objects

Hi @bsinky,

While trying to consume a Dictionary in one of my games, I ran into an interesting problem where I get a KeyNotFound exception. Here's a simplified test that reproduces the result:

    @Test
    public function getGetsValuesSetWithObjectsAsKeys()
    {
        var m1 = new Monster(7);
        var m2 = new Monster(3);
        var m3 = new Monster(3);
        var m4 = new Monster(3);

        var dictionary = new Dictionary<Monster, Int>();
        dictionary[m1] = 0;
        dictionary[m2] = 0;
        dictionary[m3] = 0;
        dictionary[m4] = 0;
        
        Assert.that(dictionary[m1], Is.equalTo(0));
        Assert.that(dictionary[m2], Is.equalTo(0));
        Assert.that(dictionary[m3], Is.equalTo(0));
        Assert.that(dictionary[m4], Is.equalTo(0));
    }

Helper class:

class Monster
{
    private var value:Int;

    public function new(value:Int)
    {
        this.value = value;
    }
}

Exception stack:

    ERROR: massive.munit.UnhandledException: The given key ({ value => 7 }) was not present in the Dictionary. Keys: { next => #function:0, a => [{ value => 7 },{ value => 3 },{ value => 3 },{ value => 3 }], p => 0, hasNext => #function:0 }
from: haxesharp.exceptions.KeyNotFoundException.new() at 19


Called from /usr/share/haxe/std/haxe/ds/BalancedTree.hx line 146
Called from /usr/share/haxe/std/haxe/ds/BalancedTree.hx line 150
Called from /usr/share/haxe/std/haxe/ds/BalancedTree.hx line 84 at haxesharp.collections.DictionaryTest#getGetsValuesSetWithObjectsAsKeys at haxesharp/collections/Dictionary.hx (41)
        at haxesharp/collections/DictionaryTest.hx (186)
        at massive/munit/TestRunner.hx (330)

(I also changed the default exception to print out the key and valid key values.)

Is this something you can look into?

Create a better Timer class

The Haxe timer class does not bring me joy.

  • It starts automatically on construction
  • It can be stopped, but not started again.

This differs from practically every other programming language. Make a better timer please.

Add Dictionary Support

Motivation

As a C# developer, I find the Map class difficult to use (compiler errors about the Map sub-type are confusing; checking for specific keys/values is difficult; fetching all values is impossible).

I would like a Dictionary class that resembles what C# provides.

MVP

To support this use-case, at a minimum, we need to implement:

  • Array accessor to get and set values. Haxe supports this via the @:arrayAccess annotation.
  • containsKey(key) method
  • count property
  • keys property to get all keys
  • values property to get all values
  • Constructor with no parameters
  • Constructor that takes a Map as a parameter and uses those values
  • toMap method that returns a Map

Later, we can add support for other convenience methods as needed:

  • add(key, value) method
  • clear method
  • containsValue(value) method
  • remove(key) method

Each method can be individually added (with appropriate unit tests + docs).

Internal Design

Haxe provides a Map class with three implementations (depending on the key type). Internally, we should store things in a Map instance. (This also simplifies the constructor and toMap methods.)

We can pass the type parameters along to the Map instance constructor, and everything should Just Work.

The only real difficulty is how to efficiently retrieve all the values. We can use two Maps (one with value => key mappings) or an array with values, but this effectively doubles the required memory and forces us to keep everything synchronized. If retrieving values is an infrequent operation, it might be okay to just iterate over all keys and retrieve all values in linear time. (We can ship the MVP with this.)

Next Steps

I would approach this by implementing the following:

  • Basic Dictionary class in haxesharp.collections with a constructor and array-access to get/set values
  • Unit tests to cover the four types of Map that Haxe abstracts over:
    • Unit tests with string keys
    • Unit tests with int keys
    • Unit tests with enum values for keys
    • Unit tests with object values for keys

Once that's done, the rest of the methods should be easy to selectively implement.

@bsinky is this something you would like to work on?

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.