<commit_before>let noble = require("noble"),
    debug = require('debug')('nuimojs'),
    EventEmitter = require("events").EventEmitter;

let Device = require("./src/device.js");

let ready = false,
    wantScan = false;

noble.on("stateChange", (state) => {
    ready = (state === "poweredOn");
    if (ready) {
        if (wantScan) {
            noble.startScanning();
        }
    } else {
        noble.stopScanning();
    }
});

class Nuimo extends EventEmitter {


    constructor () {
        super();
        this._connectedDevices = [];
    }


    static get Direction () {
        return Device.Direction;
    }


    static get Swipe () {
        return Device.Swipe;
    }


    static get Fly () {
        return Device.Fly;
    }


    static get Area () {
        return Device.Area;
    }


    static get Options(){
        return Device.Options;
    }


    scan () {
        wantScan = true;

        noble.on("discover", (peripheral) => {
            let advertisement = peripheral.advertisement;

            if (advertisement.localName === "Nuimo") {
                peripheral.removeAllListeners();
                noble.stopScanning();

                let device = new Device(peripheral);

                device._peripheral.on("connect", () => {
                    debug("Peripheral connected");
                    this._connectedDevices.push(device);
                });

                device._peripheral.on("disconnect", () => {
                    debug("Peripheral disconnected");

                    if (this._connectedDevices.indexOf(device) >= 0) {
                        this._connectedDevices.splice(this._connectedDevices.indexOf(device), 1);
                    }

                    if (wantScan) {
                        noble.startScanning();
                    }

                    device.emit("disconnect");
                });

                this.emit("discover", device);
            }
        });

        if (ready) {
            noble.startScanning();
        }
    }


    wirethingInit () {
        this.scan();
    }


    stop () {
        wantScan = false;
        noble.stopScanning();
    }


    getConnectedDeviceByUUID (uuid) {
        if (this._connectedDevices.indexOf(device) >= 0) {
            return this._connectedDevices[this._connectedDevices.indexOf(device)];
        } else {
            return null;
        }
    }


}

module.exports = Nuimo;
<commit_msg>Changed _connectedDevices to a hash table rather than an array<commit_after>let noble = require("noble"),
    debug = require('debug')('nuimojs'),
    EventEmitter = require("events").EventEmitter;

let Device = require("./src/device.js");

let ready = false,
    wantScan = false;

noble.on("stateChange", (state) => {
    ready = (state === "poweredOn");
    if (ready) {
        if (wantScan) {
            noble.startScanning();
        }
    } else {
        noble.stopScanning();
    }
});

class Nuimo extends EventEmitter {


    constructor () {
        super();
        this._connectedDevices = {};
    }


    static get Direction () {
        return Device.Direction;
    }


    static get Swipe () {
        return Device.Swipe;
    }


    static get Fly () {
        return Device.Fly;
    }


    static get Area () {
        return Device.Area;
    }


    static get Options(){
        return Device.Options;
    }


    scan () {
        wantScan = true;

        noble.on("discover", (peripheral) => {
            let advertisement = peripheral.advertisement;

            if (advertisement.localName === "Nuimo") {
                peripheral.removeAllListeners();
                noble.stopScanning();

                let device = new Device(peripheral);

                device._peripheral.on("connect", () => {
                    debug("Peripheral connected");
                    this._connectedDevices[device.uuid] = device;
                });

                device._peripheral.on("disconnect", () => {
                    debug("Peripheral disconnected");
                    delete this._connectedDevices[device.uuid];

                    if (wantScan) {
                        noble.startScanning();
                    }

                    device.emit("disconnect");
                });

                this.emit("discover", device);
            }
        });

        if (ready) {
            noble.startScanning();
        }
    }


    wirethingInit () {
        this.scan();
    }


    stop () {
        wantScan = false;
        noble.stopScanning();
    }


    getConnectedDeviceByUUID (uuid) {
        return this._connectedDevices[uuid];
    }


    getConnectedDevices () {
        return Object.keys(this._connectedDevices).map((uuid) => {
            return this._connectedDevices[uuid];
        })
    }


}

module.exports = Nuimo;

{'fraction_non_alphanumeric': 0.12466349140608822, 'fraction_numerical': 0.0006212466349140609, 'mean_word_length': 1.5488126649076517, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '1473656', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1266, 'n_words': 236}