<commit_before><?php

/**
 * Hoa Framework
 *
 *
 * @license
 *
 * GNU General Public License
 *
 * This file is part of Hoa Open Accessibility.
 * Copyright (c) 2007, 2008 <NAME>. All rights reserved.
 *
 * HOA Open Accessibility is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * HOA Open Accessibility is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with HOA Open Accessibility; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *
 * @category    Framework
 * @package     Hoa_Tree
 * @subpackage  Hoa_Tree_Binary
 *
 */

/**
 * Hoa_Framework
 */
require_once 'Framework.php';

/**
 * Hoa_Tree_Exception
 */
import('Tree.Exception');

/**
 * Hoa_Tree_Abstract
 */
import('Tree.Abstract');

/**
 * Class Hoa_Tree_Binary.
 *
 * Manipulate a binary tree.
 *
 * @author      <NAME> <<EMAIL>>
 * @copyright   Copyright (c) 2007, 2008 <NAME>.
 * @license     http://gnu.org/licenses/gpl.txt GNU GPL
 * @since       PHP 5
 * @version     0.1
 * @package     Hoa_Tree
 * @subpackage  Hoa_Tree_Binary
 */

class Hoa_Tree_Binary extends Hoa_Tree_Abstract {

    /**
     * Insert a child.
     * Fill the child list from left to right.
     *
     * @access  public
     * @param   Hoa_Tree_Binary  $child    Child to insert.
     * @return  Hoa_Tree_Binary
     * @throw   Hoa_Tree_Exception
     */
    public function insert ( Hoa_Tree_Abstract $child ) {

        if(!($child instanceof Hoa_Tree_Binary))
            throw new Hoa_Tree_Exception(
                'Child must be an instance of Hoa_Tree_Binary; given %s.',
                0, get_class($child));

        if(false === $this->isSimpleLeft()) {

            $this->_childs[0] = $child;

            return $this;
        }

        if(true === $this->isSimpleLeft()) {

            $this->_childs[1] = $child;

            return $this;
        }

        throw new Hoa_Tree_Exception(
            'Cannot insert a new element: left and right child are ' .
            'already set.', 1);
    }

    /**
     * Insert the left child.
     *
     * @access  public
     * @param   Hoa_Tree_Binary  $child    Child to insert.
     * @return  Hoa_Tree_Binary
     * @throw   Hoa_Tree_Exception
     */
    public function insertLeft ( Hoa_Tree_Binary $child ) {

        if(false === $this->isSimpleLeft())
            throw new Hoa_Tree_Exception(
                'Left child is already set.', 2);

        $this->_childs[0] = $child;

        return $this;
    }

    /**
     * Insert the right child.
     *
     * @access  public<commit_msg>Correct a bug when inserting more than two nodes.<commit_after><?php

/**
 * Hoa Framework
 *
 *
 * @license
 *
 * GNU General Public License
 *
 * This file is part of Hoa Open Accessibility.
 * Copyright (c) 2007, 2008 <NAME>. All rights reserved.
 *
 * HOA Open Accessibility is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * HOA Open Accessibility is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with HOA Open Accessibility; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *
 * @category    Framework
 * @package     Hoa_Tree
 * @subpackage  Hoa_Tree_Binary
 *
 */

/**
 * Hoa_Framework
 */
require_once 'Framework.php';

/**
 * Hoa_Tree_Exception
 */
import('Tree.Exception');

/**
 * Hoa_Tree_Abstract
 */
import('Tree.Abstract');

/**
 * Class Hoa_Tree_Binary.
 *
 * Manipulate a binary tree.
 *
 * @author      <NAME> <<EMAIL>>
 * @copyright   Copyright (c) 2007, 2008 <NAME>.
 * @license     http://gnu.org/licenses/gpl.txt GNU GPL
 * @since       PHP 5
 * @version     0.1
 * @package     Hoa_Tree
 * @subpackage  Hoa_Tree_Binary
 */

class Hoa_Tree_Binary extends Hoa_Tree_Abstract {

    /**
     * Insert a child.
     * Fill the child list from left to right.
     *
     * @access  public
     * @param   Hoa_Tree_Binary  $child    Child to insert.
     * @return  Hoa_Tree_Binary
     * @throw   Hoa_Tree_Exception
     */
    public function insert ( Hoa_Tree_Abstract $child ) {

        if(!($child instanceof Hoa_Tree_Binary))
            throw new Hoa_Tree_Exception(
                'Child must be an instance of Hoa_Tree_Binary; given %s.',
                0, get_class($child));

        if(true === $this->isDouble())
            throw new Hoa_Tree_Exception(
                'Cannot insert a new element: left and right child are ' .
                'already set.', 1);

        if(false === $this->isSimpleLeft()) {

            $this->_childs[0] = $child;

            return $this;
        }

        if(true === $this->isSimpleLeft()) {

            $this->_childs[1] = $child;

            return $this;
        }
    }

    /**
     * Insert the left child.
     *
     * @access  public
     * @param   Hoa_Tree_Binary  $child    Child to insert.
     * @return  Hoa_Tree_Binary
     * @throw   Hoa_Tree_Exception
     */
    public function insertLeft ( Hoa_Tree_Binary $child ) {

        if(false === $this->isSimpleLeft())
            throw new Hoa_Tree_Exception(
                'Left child is already set.', 2);

        $this->_childs[0] = $child;

        return $this;
    }

    /**
     * Insert the right child.
     *
     * @access  public
{'fraction_non_alphanumeric': 0.10220048899755502, 'fraction_numerical': 0.01206193969030155, 'mean_word_length': 2.3203463203463204, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 26, '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': '4299944', 'n_tokens_mistral': 1895, 'n_tokens_neox': 1796, 'n_words': 611}