<commit_before>var chan = (function() {
    'use strict';
    var protocol_error = function(name, o) {
        var type = typeof o;
        if ('object' == type) {
            if (o){
                if(o.constructor === Array) {
                    type = "array";
                } else {
                    type = Object.prototype.toString.call(o);
                }
            } else {
                type = 'null';
            }
        }
        return new Error(["No protocol method ", name, " defined for type ", type, ": ", o].join(""));
    };
    var protocols = {
        MMC: {
            cleanup: function(o) {
                if (o && o.csp$channel$MMC$cleanup) {
                    return o.csp$channel$MMC$cleanup(o);
                }
                throw protocol_error('csp.channel.MMC/cleanup', o);
            }
        },
        ReadPort: {
            take: function(o, handler) {
                if (o && o.csp$channel$ReadPort$take) {
                    return o.csp$channel$ReadPort$take(o, handler);
                }
                throw protocol_error('csp.channel.ReadPort/take', o);
            }
        },
        WritePort: {
            put: function(o, val, handler) {
                if (o && o.csp$channel$WritePort$put) {
                    return o.csp$channel$WritePort$put(o, val, handler);
                }
                throw protocol_error('csp.channel.WritePort/put', o);
            }
        },
        Channel: {
            close: function(o) {
                if (o && o.csp$channel$Channel$close) {
                    return o.csp$channel$Channel$close(o);
                }
                throw protocol_error('csp.channel.Channel/close', o);
            },
            closed: function(o) {
                if (o && o.csp$channel$Channel$closed) {
                    return o.csp$channel$Channel$closed(o);
                }
                throw protocol_error('csp.channel.Channel/closed', o);
            }
        },
        Buffer: {
            full: function(o) {
                if (o && o.csp$channel$Buffer$full) {
                    return o.csp$channel$Buffer$full(o);
                }
                throw protocol_error('csp.channel.Buffer/full', o);
            },
            remove: function(o) {
                if (o && o.csp$channel$Buffer$remove) {
                    return o.csp$channel$Buffer$remove(o);
                }
                throw protocol_error('csp.channel.Buffer/remove', o);
            },
            add: function(o, item) {
                if (o && o.csp$channel$Buffer$add) {
                    return o.csp$channel$Buffer$add(o, item);
                }
                throw protocol_error('csp.channel.Buffer/add', o);
            }
        },
        Handler: {
            active: function(o) {
                if (o && o.csp$channel$Handler$active) {
                    return o.csp$channel$Handler$active(o);
                }
                throw protocol_error('csp.channel.Handler/active', o);
            },
            commit: function(o) {
                if (o && o.csp$channel$Channel$commit) {
                    return o.csp$channel$Channel$commit(o);
                }
                throw protocol_error('csp.channel.Handler/commit', o);
            }
        },
        Core: {
            deref: function(o) {
                if (o && o.csp$Core$deref) {
                    return o.csp$Core$deref(o);
                }
                throw protocol_error('csp.Core/deref', o);
            }
        },
    };

    var impl = (function(p){
        var i,j, impl = {};
        for(i in p) {
            if (p.hasOwnProperty(i)) {
                for (j in p[i]) {
                    if (p[i].hasOwnProperty(j)) {
                        impl[j] = p[i][j];
                    }
                }
            }
        }
        return impl;
    })(protocols);

    var box = function(val) {
        return {
            csp$Core$deref: function(o) {
                return val;
            }
        };
    };
    var dispatch = (function() {
        return {
            run: function(f) {
                setTimeout(f, 0);
            }
        };
    })();
    var Channel = (function(impl, box, dispatch) {
        var Channel = function(takes, puts, buffer, closed) {
            this.takes = takes;
            this.puts = puts;
            this.buffer = buffer;
            this.closed = {csp$Core$deref: function() { return closed;}};
        };

        var p = Channel.prototype;

        p.csp$channel$MMC$cleanup = function(o) {
            var i, item, tlen = o.takes.length, plen = o.puts.length;
            for(i = 0; i < plen; i++) {
                item = o.puts[i][0];
                if (! impl.active(item)) {
                    o.puts.splice(i, 1);
                }
            }
            for(i = 0; i < tlen; i++) {
                item = o.takes[i];
                if (! impl.active(item)) {
                    o.takes.splice(i, 1);
                }
            }
            return null;
        };

        p.csp$channel$WritePort$put = function(o, val, handler) {
            if (val === null) {
                throw (new Error("Cant put null in a channel"));
            }
            impl.cleanup(o);
            if (impl.closed(o)) {
                return box(null);
            } else {
                var take_cb, put_cb, taker, i, tlen = o.takes.length;
                for (i = 0; i < tlen; i++) {
                    taker = o.takes[i];
                    if (impl.active(taker) && impl.active(handler)) {
                        o.takes.splice(i, 1);
                        take_cb = impl.commit(taker);
                        put_cb = impl.commit(handler);
                        break;
                    }
                }
                if (take_cb && put_cb) {
                    dispatch.run(function() { return take_cb(val);});
                    return box(null);
                } else {
                    if (o.buffer && impl.full(o.buffer)) {
                        if (impl.active(handler) && impl.commit(handler)) {
                            impl.add(o.buffer, val);
                            return box(null);
                        }
                        return null;
                    } else {<commit_msg>Fixed bug where the buffer was only written to if it was full<commit_after>var chan = (function() {
    'use strict';
    var protocol_error = function(name, o) {
        var type = typeof o;
        if ('object' == type) {
            if (o){
                if(o.constructor === Array) {
                    type = "array";
                } else {
                    type = Object.prototype.toString.call(o);
                }
            } else {
                type = 'null';
            }
        }
        return new Error(["No protocol method ", name, " defined for type ", type, ": ", o].join(""));
    };
    var protocols = {
        MMC: {
            cleanup: function(o) {
                if (o && o.csp$channel$MMC$cleanup) {
                    return o.csp$channel$MMC$cleanup(o);
                }
                throw protocol_error('csp.channel.MMC/cleanup', o);
            }
        },
        ReadPort: {
            take: function(o, handler) {
                if (o && o.csp$channel$ReadPort$take) {
                    return o.csp$channel$ReadPort$take(o, handler);
                }
                throw protocol_error('csp.channel.ReadPort/take', o);
            }
        },
        WritePort: {
            put: function(o, val, handler) {
                if (o && o.csp$channel$WritePort$put) {
                    return o.csp$channel$WritePort$put(o, val, handler);
                }
                throw protocol_error('csp.channel.WritePort/put', o);
            }
        },
        Channel: {
            close: function(o) {
                if (o && o.csp$channel$Channel$close) {
                    return o.csp$channel$Channel$close(o);
                }
                throw protocol_error('csp.channel.Channel/close', o);
            },
            closed: function(o) {
                if (o && o.csp$channel$Channel$closed) {
                    return o.csp$channel$Channel$closed(o);
                }
                throw protocol_error('csp.channel.Channel/closed', o);
            }
        },
        Buffer: {
            full: function(o) {
                if (o && o.csp$channel$Buffer$full) {
                    return o.csp$channel$Buffer$full(o);
                }
                throw protocol_error('csp.channel.Buffer/full', o);
            },
            remove: function(o) {
                if (o && o.csp$channel$Buffer$remove) {
                    return o.csp$channel$Buffer$remove(o);
                }
                throw protocol_error('csp.channel.Buffer/remove', o);
            },
            add: function(o, item) {
                if (o && o.csp$channel$Buffer$add) {
                    return o.csp$channel$Buffer$add(o, item);
                }
                throw protocol_error('csp.channel.Buffer/add', o);
            }
        },
        Handler: {
            active: function(o) {
                if (o && o.csp$channel$Handler$active) {
                    return o.csp$channel$Handler$active(o);
                }
                throw protocol_error('csp.channel.Handler/active', o);
            },
            commit: function(o) {
                if (o && o.csp$channel$Channel$commit) {
                    return o.csp$channel$Channel$commit(o);
                }
                throw protocol_error('csp.channel.Handler/commit', o);
            }
        },
        Core: {
            deref: function(o) {
                if (o && o.csp$Core$deref) {
                    return o.csp$Core$deref(o);
                }
                throw protocol_error('csp.Core/deref', o);
            }
        },
    };

    var impl = (function(p){
        var i,j, impl = {};
        for(i in p) {
            if (p.hasOwnProperty(i)) {
                for (j in p[i]) {
                    if (p[i].hasOwnProperty(j)) {
                        impl[j] = p[i][j];
                    }
                }
            }
        }
        return impl;
    })(protocols);

    var box = function(val) {
        return {
            csp$Core$deref: function(o) {
                return val;
            }
        };
    };
    var dispatch = (function() {
        return {
            run: function(f) {
                setTimeout(f, 0);
            }
        };
    })();
    var Channel = (function(impl, box, dispatch) {
        var Channel = function(takes, puts, buffer, closed) {
            this.takes = takes;
            this.puts = puts;
            this.buffer = buffer;
            this.closed = {csp$Core$deref: function() { return closed;}};
        };

        var p = Channel.prototype;

        p.csp$channel$MMC$cleanup = function(o) {
            var i, item, tlen = o.takes.length, plen = o.puts.length;
            for(i = 0; i < plen; i++) {
                item = o.puts[i][0];
                if (! impl.active(item)) {
                    o.puts.splice(i, 1);
                }
            }
            for(i = 0; i < tlen; i++) {
                item = o.takes[i];
                if (! impl.active(item)) {
                    o.takes.splice(i, 1);
                }
            }
            return null;
        };

        p.csp$channel$WritePort$put = function(o, val, handler) {
            if (val === null) {
                throw (new Error("Cant put null in a channel"));
            }
            impl.cleanup(o);
            if (impl.closed(o)) {
                return box(null);
            } else {
                var take_cb, put_cb, taker, i, tlen = o.takes.length;
                for (i = 0; i < tlen; i++) {
                    taker = o.takes[i];
                    if (impl.active(taker) && impl.active(handler)) {
                        o.takes.splice(i, 1);
                        take_cb = impl.commit(taker);
                        put_cb = impl.commit(handler);
                        break;
                    }
                }
                if (take_cb && put_cb) {
                    dispatch.run(function() { return take_cb(val);});
                    return box(null);
                } else {
                    if (o.buffer && (! impl.full(o.buffer))) {
                        if (impl.active(handler) && impl.commit(handler)) {
                            impl.add(o.buffer, val);
                            return box(null);
                        }
                        return null;
                    } else {
{'fraction_non_alphanumeric': 0.129242614707731, 'fraction_numerical': 0.001257071024512885, 'mean_word_length': 1.0704294079375407, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3126113', 'n_tokens_mistral': 3706, 'n_tokens_neox': 3497, 'n_words': 672}