calculating rank

16 views
Skip to first unread message

acarrico

unread,
Nov 10, 2011, 2:15:19 PM11/10/11
to Flapjax
I'm confused. Shouldn't an EventStream's rank be one plus the max rank
of its sources? In reality, I think each EventStream is just assigned
from an ever increasing counter. Does node creation order work just as
well as rank for the propagation algorithm? Look at my annotations in
the rank
calculation of flapjax-2.1.js:

...
var lastRank = 0;

...
//Event: Array Node b * ( (Pulse a -> Void) * Pulse b -> Void)
var EventStream = function (nodes,updater) {
this.updater = updater;

this.sendsTo = []; //forward link
this.weaklyHeld = false;

for (var i = 0; i < nodes.length; i++) {
nodes[i].attachListener(this);
}

this.rank = ++lastRank;
// *** acarrico: this is just an increasing counter:
alert(this.rank);
};
EventStream.prototype = new Object();

...
var genericAttachListener = function(node, dependent) {
node.sendsTo.push(dependent);

// *** acarrico: Isn't dependent.rank uninitialized here? And
// *** anyway, what is this calculation supposed to do?
if(node.rank > dependent.rank) {
var lowest = lastRank+1;
var q = [dependent];
while(q.length) {
var cur = q.splice(0,1)[0];
cur.rank = ++lastRank;
q = q.concat(cur.sendsTo);
}
}
};

--
Anthony Carrico

Aran Donohue

unread,
Nov 11, 2011, 12:29:22 AM11/11/11
to fla...@googlegroups.com, Flapjax
Hey,

You can attach an earlier-created node as a listener to a later-created node.

The calculation raises the rank of the listener. Now that it has been raised, everything that listens to it must be raised too.

Aran

> --
> Flapjax home page: www.flapjax-lang.org
> Flapjax list: groups.google.com/group/flapjax
> Post: fla...@googlegroups.com
> Unsubscribe: flapjax-u...@googlegroups.com

acarrico

unread,
Nov 11, 2011, 11:11:26 AM11/11/11
to Flapjax
On Nov 11, 12:29 am, Aran Donohue <aran.dono...@gmail.com> wrote:
> You can attach an earlier-created node as a listener to a later-created node...

Ah, that makes perfect sense. Thank you.

BTW, if anyone ever plans to iterate the library, here are my notes
from reading the code (so far):
* initialize EventStream.rank before calling attachListener to avoid
comparison with 'undefined'
* "var lowest" in attachListener is dead code
* "var len" in propagatePulse is redundant with queue.isEmpty

Arjun Guha

unread,
Dec 24, 2011, 11:50:07 PM12/24/11
to fla...@googlegroups.com
Thanks! Incorporated.

Reply all
Reply to author
Forward
0 new messages