Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
11 / 11
ByteMatrix
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
11 / 11
 __construct($dimension)
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 getSize()
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 get($line, $column)
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 set($line, $column, $value)
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
6 / 6
<?php
/*
 * Mondrian
 */
namespace Trismegiste\Mondrian\Algebra;
/**
 * ByteMatrix is a compressed matrix of unsigned shortint
 *
 * @author florent
 */
class ByteMatrix implements Matrix
{
    const CHAR_PER_COEFF = 4;
    protected $dimension;
    protected $content;
    /**
     * build a square matrix
     *
     * @param int $dimension size of matrix
     */
    public function __construct($dimension)
    {
        $this->content = str_repeat(0, self::CHAR_PER_COEFF * $dimension * $dimension);
        $this->dimension = $dimension;
    }
    /**
     * {@inheritDoc}
     */
    public function getSize()
    {
        return $this->dimension;
    }
    /**
     * {@inheritDoc}
     */
    public function get($line, $column)
    {
        return hexdec(substr($this->content, self::CHAR_PER_COEFF * ($line * $this->dimension + $column), self::CHAR_PER_COEFF));
    }
    /**
     * {@inheritDoc}
     */
    public function set($line, $column, $value)
    {
        $delta = self::CHAR_PER_COEFF * ($line * $this->dimension + $column);
        $hex = sprintf('%0' . self::CHAR_PER_COEFF . 'x', $value);
        for ($i = 0; $i < self::CHAR_PER_COEFF; $i++) {
            $this->content[$delta + $i] = $hex[$i];
        }
    }
}