Skip to content

A few bugs in LinkedVector #1

@seaders

Description

@seaders

Hey skyboy, huge thanks for the code, but there's definitely a few places where it's falling down.

First is the static emptyNode (line 30, line 36 and a few other places). It's a nice idea, but if you for instance, filter in one LinkedVector, then in that, map another LinkedVector, because they were both set to use the same node, it messed the whole thing up, quite a few runtime errors. I initially just got rid of the private static version of it, but then I realised if you did the same thing for a one instance of a LinkedVector, filter, then inside map it, you'd have the same problem. I got rid of any static entries of emptyNode and now with each function that used it, they create their own 'emptyNode' and all logic now works correctly.

Next is in the constructor of LinkedVector, in 2 lines (line 63 & 64), there's "if (values.length > 1) { if (values == 1)...", I've changed that first check to values.length > 0 and it now seems to work correctly, but I wanted to highlight it to you.

Last place where I'm having problems is splice.

I think rather than going through the problems, a list of where things go wrong might be more helpful to you, so here's the tests I ran,

        var lv:LinkedVector = new LinkedVector();
        for(var i:int = 19; i < 22; ++i)
            lv.push({"a": i, "b": "" + i});

// lv.splice(0, 0);
//all ok, len: 3
// lv.splice(0, 0, {"a": 99, "b": 22}, {"a": 101, "b": 102});
//all ok, len: 5
// lv.splice(0, 2);
//TypeError: Error #1009: Cannot access a property or method of a null object reference.
//at linkedlist.skyboy::LinkedVector/splice()[C:\dev\repos\git\peggleSocialService\frontend\game\src\linkedlist\skyboy\LinkedVector.as:638]
// lv.splice(0, 2, {"a": 99, "b": 22}, {"a": 101, "b": 102});
//all ok, len: 3
// lv.splice(0, 20);
//all ok, len: 0
// lv.splice(0, 20, {"a": 99, "b": 22}, {"a": 101, "b": 102});
//all ok, len: 2
// lv.splice(1, 0);
//all ok, len: 3
// lv.splice(1, 0, {"a": 99, "b": 22}, {"a": 101, "b": 102});
//all ok, len: 5
// lv.splice(1, 1);
//TypeError: Error #1009: Cannot access a property or method of a null object reference.
//at linkedlist.skyboy::LinkedVector/splice()[C:\dev\repos\git\peggleSocialService\frontend\game\src\linkedlist\skyboy\LinkedVector.as:648]
// lv.splice(1, 1, {"a": 99, "b": 22}, {"a": 101, "b": 102});
//ran, but very wrong, length: 6, but only has 1 item, the very first, {a: 19, b: 19}

As you can see, it acts quite irrationally at more than a few points. Currently we're just avoiding splice, before we try and rewrite it, but again I wanted to bring the issues to you.

Thanks, seaders.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions