<commit_before>import React, {Component, PropTypes} from 'react';

import LC3 from '../../core/lc3';

import { Table } from 'react-bootstrap';
import {MemoryRow, MemoryHeaderRow} from './MemoryRow';

export default class MemoryTable extends Component {

    render() {
        const {lc3, topRow: nominalTopRow} = this.props;
        const {memory, symbolTable} = lc3;

        const rowsToShow = 16;
        const topRow = Math.min(nominalTopRow, memory.size - rowsToShow);
        const memoryInView = memory.skip(topRow).take(rowsToShow);

        const activeRow = lc3.registers.pc;

        const memoryRows = memoryInView.map((value, index) => {
            const address = topRow + index;
            return <MemoryRow
                address={address}
                value={value}
                label={symbolTable.keyOf(address)}
                active={address === activeRow}
                instruction={lc3.formatInstructionAtAddress(address)}
                onSetPC={() => this.props.onSetPC(address)}
                onSetValue={(value) => this.props.onSetMemory(address, value)}
                key={index}
            />;
        });

        return <Table hover>
            <thead>
                <MemoryHeaderRow />
            </thead>
            <tbody>
                {memoryRows}
            </tbody>
        </Table>;
    }
<commit_msg>Make memory slicing a bit more robust<commit_after>import React, {Component, PropTypes} from 'react';

import LC3 from '../../core/lc3';

import { Table } from 'react-bootstrap';
import {MemoryRow, MemoryHeaderRow} from './MemoryRow';

export default class MemoryTable extends Component {

    render() {
        const {lc3, topRow: nominalTopRow} = this.props;
        const {memory, symbolTable} = lc3;

        const rowsToShow = 16;
        const topRow = Math.min(nominalTopRow, memory.size - rowsToShow);

        let addressesToShow = Array(rowsToShow);
        for (let i = 0; i < rowsToShow; i++) {
            addressesToShow[i] = topRow + i;
        }

        const activeRow = lc3.registers.pc;
        const memoryRows = addressesToShow.map((address, index) => {
            return <MemoryRow
                address={address}
                value={memory.get(address)}
                label={symbolTable.keyOf(address)}
                active={address === activeRow}
                instruction={lc3.formatInstructionAtAddress(address)}
                onSetPC={() => this.props.onSetPC(address)}
                onSetValue={(value) => this.props.onSetMemory(address, value)}
                key={index}
            />;
        });

        return <Table hover>
            <thead>
                <MemoryHeaderRow />
            </thead>
            <tbody>
                {memoryRows}
            </tbody>
        </Table>;
    }

{'fraction_non_alphanumeric': 0.1197158081705151, 'fraction_numerical': 0.006039076376554174, 'mean_word_length': 1.873469387755102, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 25, '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': '4723689', 'n_tokens_mistral': 785, 'n_tokens_neox': 750, 'n_words': 174}