<commit_before><?php

namespace Kevinrob\GuzzleCache;


class KeyValueHttpHeader
{
    const REGEX_SPLIT = '/^([^=]*)=(.*)$/';

    /**
     * @var string[]
     */
    protected $values = [];


    /**
     * @param array $values
     */
    public function __construct(array $values)
    {
        foreach ($values as $key => $value) {
            $exploded = explode(',', $value);

            if (count($exploded) > 1) {
                // contain a comma!
                unset($values[$key]);
                $values = array_merge($values, $exploded);
            }
        }

        foreach ($values as $value) {
            $matches = [];
            if (preg_match(self::REGEX_SPLIT, $value, $matches)) {
                $this->values[trim($matches[1])] = trim($matches[2]);
            } else {
                $this->values[trim($value)] = true;
            }
        }
    }

    /**
     * @param string $key
     * @return bool
     */
    public function has($key)
    {
        // For performance, we can use isset,
        // but it will not match if value == 0
        return isset($this->values[$key]) || array_key_exists($key, $this->values);
    }

    /**
     * @param string $key
     * @return string
     */
    public function get($key)
    {
        if ($this->has($key)) {
            return $this->values[$key];
        }

        return "";
    }

}
<commit_msg>Remove O(n^2) for O(n*m)<commit_after><?php

namespace Kevinrob\GuzzleCache;


class KeyValueHttpHeader
{
    const REGEX_SPLIT = '/^([^=]*)=(.*)$/';

    /**
     * @var string[]
     */
    protected $values = [];


    /**
     * @param array $values
     */
    public function __construct(array $values)
    {
        foreach ($values as $value) {
            $exploded = explode(',', $value);

            foreach ($exploded as $fragment) {
                $matches = [];
                if (preg_match(self::REGEX_SPLIT, $fragment, $matches)) {
                    $this->values[trim($matches[1])] = trim($matches[2]);
                } else {
                    $this->values[trim($fragment)] = true;
                }
            }
        }
    }

    /**
     * @param string $key
     * @return bool
     */
    public function has($key)
    {
        // For performance, we can use isset,
        // but it will not match if value == 0
        return isset($this->values[$key]) || array_key_exists($key, $this->values);
    }

    /**
     * @param string $key
     * @return string
     */
    public function get($key)
    {
        if ($this->has($key)) {
            return $this->values[$key];
        }

        return "";
    }

}

{'fraction_non_alphanumeric': 0.16439909297052155, 'fraction_numerical': 0.0030234315948601664, 'mean_word_length': 1.5699029126213593, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '4091142', 'n_tokens_mistral': 822, 'n_tokens_neox': 789, 'n_words': 170}