Skip to content

Instantly share code, notes, and snippets.

type SubseqAsyncResult = {
sequence: string;
matches: Array<{
string: string,
score: number,
positions: number[]
}>;
};
type SubseqStringTableEntry = {
# https://blogs.msdn.microsoft.com/jeuge/2005/05/03/bit-fiddling-2/
fast = do ->
t = [
0
1
1,2
1,2,2,3
1,2,2,3,2,3,3,4
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6
function swap<K, V>(indexA: number, indexB: number): void {
const k: K = this.keys[indexA];
const v: V = this.vals[indexA];
this.keys[indexA] = this.keys[indexB];
this.vals[indexA] = this.vals[indexB];
this.keys[indexB] = k;
this.vals[indexB] = v;
}
abstract class PriorityQueue<K, V> {

Laziness

Channel operations receive and send are performed eagerly, i.e., for the current process, each application of the ioc loop greedily performs as many yielding operations as possible, and will break only after encountering a channel that causes the process to block.

Alternatively a process may be run lazily, by including the yield proc expression, which forces control to be yielded back to the scheduler, and re-enqueues the process at the end of the global run queue.

{proc, chan, receive, send, mult} = require './'
{Generator, isGenerator, compareAndSwap} = require './helpers'
{inspect} = require 'util'



module.exports =

Agent

@nickfargo
nickfargo / channel-delegate.litcoffee
Last active September 4, 2015 22:54
Delegation protocol for Channel to be proxied by arbitrary objects
class Channel

Channel.delegate

Implement the channel I/O protocol on a target object, by furnishing it with methods that delegate both to a backing entity referenced by property target[inName] for its input aspects, and to one referenced by target[outName] for its output aspects. If only one property name is provided, then both input and output are delegated to the same backing entity.

  @delegate = (target, inName, outName) =>
    @delegate.input target, inName
    @delegate.output target, outName ? inName

Update 2015-08-24

merge = (channels, into) ->
  out = into ? chan()
  sem = channels.length
  results = []
  add = (ch) ->
    until final value = yield receive ch
      yield send out, value
    results.push value

Both core.async and js-csp reverted their “promise channel” implementation. Reasoning given appears to reference this issue.

However, the described anomalous behavior does not appear to be present in prochan, as demonstrated by this case added to test suite:

  it "keeps its promises", async ->
    ch = chan.promise()

    p1 = proc ->
 value = yield receive ch
@nickfargo
nickfargo / instant-coffee.md
Last active January 2, 2016 10:52
The minimalist fast-track to fluency in CoffeeScript

Instant Coffee

CoffeeScript ⇒ JavaScript


  1. Arrows, not function:
  • e.g. ->, (a) ->, (a,b) ->, curried = (a) -> (b) -> ···
  • => binds this from outer scope
  • generator function if body contains yield

Multicast generator logic expressed both as a generator function, and as a manually coded state-machine class. Adding the latter to prochan library; this allows the uglify'd bundle to target pre-ES6.

{proc, chan, receive, send} = require './'
{pooled, AbstractGenerator} = require './helpers'



module.exports =