/*
@markov - the markov order to use for this jsMegaHal instance, defaults to 4
967823
function jsMegaHal(markov, defaultReply) {
      this.markov = markov != null ? markov : 4;
      this.defaultReply = defaultReply != null ? defaultReply : '';
      this.words = Object.create(null);
      this.quads = {};
      this.next = {};
      this.prev = {};
    }
1271204
function order(type, name) {
  if (type === '' || type === 'M') return name;
  if (type === 'm') return type + name;
  if (type === 'aug') return name + '#5';
  if (type === 'm#5') return 'm' + name + '#5';
  if (type === 'dim') return name === 'b7' ? 'dim7' : 'm' + name + 'b5';
  if (type === 'Mb5') return name + 'b5';
  else return name + type;
}
891676
function preferencesReload() {
    return this.initializedPromise.then(function () {
      this._readFromStorage(DEFAULT_PREFERENCES).then(function(prefObj) {
        if (prefObj) {
          this.prefs = prefObj;
        }
      }.bind(this));
    }.bind(this));
  }
422250
function(state0, action0, reward0, state1) {
    this.state0 = state0;
    this.action0 = action0;
    this.reward0 = reward0;
    this.state1 = state1;
  }
951168
def build_markov(cursor, cmdchar, ctrlchan, speaker=None, initial_run=False, debug=False):
    """"""
    if initial_run:
        cursor.query(Babble_last).delete()
    lastrow = cursor.query(Babble_last).first()
    if not lastrow:
        lastrow = Babble_last(last=0)
        cursor.add(lastrow)
    t = time.time()  # for debug
    messages = get_messages(cursor, cmdchar, ctrlchan, speaker, lastrow.last)
    # FIXME: count can be too low if speaker is not None
    curr = messages[-1].id if messages else None
    markov = generate_markov(cursor, 1, messages, initial_run)
    markov2 = generate_markov(cursor, 2, messages, initial_run)
    if debug:
        print('Generated markov in %f' % (time.time() - t))
        t = time.time()
    data, count_data = build_rows(cursor, 1, markov, initial_run)
    data2, count_data2 = build_rows(cursor, 2, markov2, initial_run)
    if debug:
        print('Rows built in %f' % (time.time() - t))
    if initial_run:
        t = time.time()  # for debug
        delete_tables(cursor)
        if debug:
            print('Tables deleted in %f' % (time.time() - t))
    t = time.time()  # for debug
    if initial_run and cursor.bind.dialect.name == 'postgresql':
        postgres_hack(cursor, 1, data)
        postgres_hack(cursor, 2, data2)
    else:
        data = [{'source': x[0], 'target': x[1], 'key': x[2], 'word': x[3], 'freq': x[4]} for x in data]
        cursor.bulk_insert_mappings(Babble, data)
        data2 = [{'source': x[0], 'target': x[1], 'key': x[2], 'word': x[3], 'freq': x[4]} for x in data2]
        cursor.bulk_insert_mappings(Babble2, data2)
    cursor.bulk_insert_mappings(Babble_count, count_data)
    cursor.bulk_insert_mappings(Babble_count, count_data2)
    if debug:
        print('Inserted rows in %f' % (time.time() - t))
    if curr is not None:
        lastrow.last = curr
    if initial_run:
        if debug:
            t = time.time()
        key_index = Index('ix_babble_key', Babble.key)
        key_index2 = Index('ix_babble2_key', Babble2.key)
        key_index.create(cursor.connection())
        key_index2.create(cursor.connection())
        if debug:
            print('Created index in %f' % (time.time() - t))
    t = time.time()  # for debug
    cursor.commit()
    if debug:
        print('Commited in %f' % (time.time() - t))
993530
function seq() {
        var rules = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            rules[_i - 0] = arguments[_i];
        }
        var rs = rules.map(RuleTypeToRule);
        if (rs.length == 0)
            throw new Error("At least one rule is expected when calling `seq`");
        if (rs.length == 1)
            return rs[0];
        var rule1 = rs[0];
        var rule2 = seq.apply(void 0, rs.slice(1));
        if (rule1.nonAdvancing && rule2 instanceof Advance)
            return new AdvanceIf(rule1);
        else
            return new Sequence(rule1, rule2);
    }
889141
@Override
	public final void setJMSPriority(int priority) throws JMSException
    {
        if (priority < 0 || priority > 9)
            throw new FFMQException("Invalid priority value : "+priority,"INVALID_PRIORITY");
            
        assertDeserializationLevel(MessageSerializationLevel.FULL);
        this.priority = priority;
    }
409001
function(memory) {
        var memoryHistory = this.get('memory');

        if (!memoryHistory) {
            memoryHistory = [];
            this.set({
                memory: memoryHistory
            });
        }

        memoryHistory.push(memory);
        while (memoryHistory.length > this._statHistory) {
            memoryHistory.shift();
        }

        var avg = 0;
        memoryHistory.filter(function(f) {
            return f !== null;
        }).forEach(function(f) {
            avg += f;
        });
        avg /= memoryHistory.length;
        this.set({
            avgMemory: Math.round(avg)
        });
    }
545781
function DASSequence(name, start, end, alpha, seq) {
    this.name = name;
    this.start = start;
    this.end = end;
    this.alphabet = alpha;
    this.seq = seq;
}
838998
private S mostLikelyState() {
        // Otherwise an HMM break would have occurred and message would be null.
        assert !message.isEmpty();

        S result = null;
        double maxLogProbability = Double.NEGATIVE_INFINITY;
        for (Map.Entry<S, Double> entry : message.entrySet()) {
            if (entry.getValue() > maxLogProbability) {
                result = entry.getKey();
                maxLogProbability = entry.getValue();
            }
        }

        assert result != null; // Otherwise an HMM break would have occurred.
        return result;
    }
496805
def populate_markov_sum
    @markov_weighted_sum = {}
    @markov_chains.each do |word,followers|
      @markov_weighted_sum[word] = followers.inject(0) {|sum,kv| sum + kv[1]}
    end
  end
589138
function preferencesReload() {
          return this.initializedPromise.then(function () {
            this._readFromStorage(this.defaults).then(function (prefObj) {
              if (prefObj) {
                this.prefs = prefObj;
              }
            }.bind(this));
          }.bind(this));
        }
554527
function ChainState() {
  if (!(this instanceof ChainState))
    return new ChainState();

  this.startHeight = -1;
  this.startHash = encoding.NULL_HASH;
  this.height = -1;
  this.marked = false;
}
847864
function () {
            var $pages = this.$pages,
                index = this.state.currentPage - 1,
                next = index + 1,
                prev = index - 1,
                buffer = 20;

            // @TODO: optimize this a bit
            // add/removeClass is expensive, so try using hasClass
            $pages.removeClass(PRESENTATION_CSS_CLASSES);
            if (this.twoPageMode) {
                next = index + 2;
                prev = index - 2;
                $pages.slice(Math.max(prev, 0), index).addClass(CSS_CLASS_PAGE_PREV);
                $pages.slice(next, next + 2).addClass(CSS_CLASS_PAGE_NEXT);
            } else {
                if (prev >= 0) {
                    $pages.eq(prev).addClass(CSS_CLASS_PAGE_PREV);
                }
                if (next < this.numPages) {
                    $pages.eq(next).addClass(CSS_CLASS_PAGE_NEXT);
                }
            }
            $pages.slice(0, index).addClass(CSS_CLASS_PAGE_BEFORE);
            $pages.slice(Math.max(0, index - buffer), index).addClass(CSS_CLASS_PAGE_BEFORE_BUFFER);
            $pages.slice(next).addClass(CSS_CLASS_PAGE_AFTER);
            $pages.slice(next, Math.min(this.numPages, next + buffer)).addClass(CSS_CLASS_PAGE_AFTER_BUFFER);

            /*
            // OPTIMIZATION CODE NOT YET WORKING PROPERLY
            $pages.slice(0, index).each(function () {
                var $p = $(this),
                    i = $p.index(),
                    toAdd = '',
                    toRm = '';
                if (!$p.hasClass(beforeClass.trim())) toAdd += beforeClass;
                if ($p.hasClass(nextClass.trim())) toRm += nextClass;
                if ($p.hasClass(afterClass.trim())) toRm += afterClass;
                if ($p.hasClass(afterBufferClass.trim())) toRm += afterBufferClass;
                if (i >= index - buffer && !$p.hasClass(beforeBufferClass.trim()))
                    toAdd += beforeBufferClass;
                else if ($p.hasClass(beforeBufferClass.trim()))
                    toRm += beforeBufferClass;
                if (i >= prev && !$p.hasClass(prevClass.trim()))
                    toAdd += prevClass;
                else if ($p.hasClass(prevClass.trim()))
                    toRm += prevClass;
                $p.addClass(toAdd).removeClass(toRm);
//                console.log('before', $p.index(), toRm, toAdd);
            });
            $pages.slice(next).each(function () {
                var $p = $(this),
                    i = $p.index(),
                    toAdd = '',
                    toRm = '';
                if (!$p.hasClass(afterClass.trim())) toAdd += afterClass;
                if ($p.hasClass(prevClass.trim())) toRm += prevClass;
                if ($p.hasClass(beforeClass.trim())) toRm += beforeClass;
                if ($p.hasClass(beforeBufferClass.trim())) toRm += beforeBufferClass;
                if (i <= index + buffer && !$p.hasClass(afterBufferClass.trim()))
                    toAdd += afterBufferClass;
                else if ($p.hasClass(afterBufferClass.trim()))
                    toRm += afterBufferClass;
                if (i <= next + 1 && !$p.hasClass(nextClass.trim()))
                    toAdd += nextClass;
                else if ($p.hasClass(nextClass.trim()))
                    toRm += nextClass;
                $p.addClass(toAdd).removeClass(toRm);
//                console.log('after', $p.index(), toRm, toAdd);
            });*/
        }
332582
function markOnce (
  tree,
  index,
  key
) {
  markStatic(tree, `__once__${index}${key ? `_${key}` : ``}`, true);
  return tree
}
956630
@Override
	public OMVRBTreeEntryMemory<K, V> getNextInMemory() {
		OMVRBTreeEntryMemory<K, V> t = this;
		OMVRBTreeEntryMemory<K, V> p = null;

		if (t.right != null) {
			p = t.right;
			while (p.left != null)
				p = p.left;
		} else {
			p = t.parent;
			while (p != null && t == p.right) {
				t = p;
				p = p.parent;
			}
		}

		return p;
	}
172606
function(m) {
	console.log([m.a, m.b, m.c, m.d, m.e, m.f]);
}