<commit_before>import { combineReducers } from 'redux';

import {
  WEAVE_ON, WEAVE_OFF,
  THREADING_ON, THREADING_OFF,
  TREADLING_ON, TREADLING_OFF,
  TIE_UP_ON, TIE_UP_OFF} from '../constants';

const initialState = {
  weaves: [],
  numberOfWeaves: 0,
  threadings: [],
  treadlings: [],
  tieUp: []
};

function initNewState(state) {
  return Object.assign({}, state,
    {
      weaves: [...state.weaves],
      numberOfWeaves: state.numberOfWeaves,
      threadings: [...state.threadings],
      treadlings: [...state.treadlings],
      tieUp: [...state.tieUp]
    }
  );
}

function switcherWeaveOn(newState, action) {
  newState.numberOfWeaves++;

  if (newState.weaves[action.row] === undefined)
    newState.weaves[action.row] = [];

  newState.weaves[action.row][action.col] = true;
  return newState;
}

function switcherWeaveOff(newState, action) {
  newState.numberOfWeaves--;

  if (newState.weaves[action.row] === undefined)
    newState.weaves[action.row] = [];

  newState.weaves[action.row][action.col] = false;
  return newState;
}

function switcherTieUpOn(newState, action) {
  if (newState.tieUp[action.row] === undefined)
    newState.tieUp[action.row] = [];

  newState.tieUp[action.row][action.col] = true;
  return newState;
}

function switcherTieUpOff(newState, action) {
  if (newState.tieUp[action.row] === undefined)
    newState.tieUp[action.row] = [];

  newState.tieUp[action.row][action.col] = false;
  return newState;
}

function switcherThreadingOn(newState, action) {
  newState.threadings[action.col] = action.row;
  return newState;
}

function switcherThreadingOff(newState, action) {
  newState.threadings[action.col] = undefined;
  return newState;
}

function switcherTreadlingOn(newState, action) {
  newState.treadlings[action.col] = action.row;
  return newState;
}

function switcherTreadlingOff(newState, action) {
  newState.treadlings[action.col] = undefined;<commit_msg>Add primitive intersection for Weave<commit_after>import { combineReducers } from 'redux';

import {
  WEAVE_ON, WEAVE_OFF,
  THREADING_ON, THREADING_OFF,
  TREADLING_ON, TREADLING_OFF,
  TIE_UP_ON, TIE_UP_OFF} from '../constants';

const initialState = {
  weaves: [],
  numberOfWeaves: 0,
  threadings: [],
  treadlings: [],
  tieUp: []
};

function initNewState(state) {
  return Object.assign({}, state,
    {
      weaves: [...state.weaves],
      numberOfWeaves: state.numberOfWeaves,
      threadings: [...state.threadings],
      treadlings: [...state.treadlings],
      tieUp: [...state.tieUp]
    }
  );
}

function switcherWeaveOn(newState, action) {
  newState.numberOfWeaves++;

  if (newState.weaves[action.row] === undefined)
    newState.weaves[action.row] = [];

  newState.weaves[action.row][action.col] = true;
  return newState;
}

function switcherWeaveOff(newState, action) {
  newState.numberOfWeaves--;

  if (newState.weaves[action.row] === undefined)
    newState.weaves[action.row] = [];

  newState.weaves[action.row][action.col] = false;
  return newState;
}

function checkThreading(newState, row) {
  for (let i = 0; i < newState.threadings.length; i++) {
    if (newState.threadings[i] === row) return i;
  }

  return -1;
}

function checkTreadling(newState, col) {
  for (let i = 0; i < newState.treadlings.length; i++) {
    if (newState.treadlings[i] === col) return i;
  }

  return -1;
}

function switcherTieUpOn(newState, action) {
  if (newState.tieUp[action.row] === undefined)
    newState.tieUp[action.row] = [];

  newState.tieUp[action.row][action.col] = true;

  const weaveCol = checkThreading(newState, action.row);
  const weaveRow = checkTreadling(newState, action.col);

  if (weaveRow > -1 && weaveCol > -1) {
    if (newState.weaves[weaveRow] === undefined) newState.weaves[weaveRow] = [];
    newState.weaves[weaveRow][weaveCol] = true;
  }

  return newState;
}

function switcherTieUpOff(newState, action) {
  if (newState.tieUp[action.row] === undefined)
    newState.tieUp[action.row] = [];

  newState.tieUp[action.row][action.col] = false;

  const weaveCol = checkThreading(newState, action.row);
  const weaveRow = checkTreadling(newState, action.col);

  if (weaveRow > -1 && weaveCol > -1) {
    if (newState.weaves[weaveRow] === undefined) newState.weaves[weaveRow] = [];
    newState.weaves[weaveRow][weaveCol] = false;
  }

  return newState;
}

function switcherThreadingOn(newState, action) {
  newState.threadings[action.col] = action.row;
  return newState;
}

function switcherThreadingOff(newState, action) {
  newState.threadings[action.col] = undefined;
  return newState;
}

function switcherTreadlingOn(newState, action) {
  newState.treadlings[action.col] = action.row;
  return newState;
}

function switcherTreadlingOff(newState, action) {
  newState.treadlings[action.col] = undefined;
{'fraction_non_alphanumeric': 0.14524207011686144, 'fraction_numerical': 0.002086811352253756, 'mean_word_length': 4.261251372118551, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3678015', 'n_tokens_mistral': 1758, 'n_tokens_neox': 1729, 'n_words': 295}