public function registerNS(string $ns, string $path, $standard = Autoloader::PSR4)
    {
        if (!file_exists($path) || !is_dir($path) || !is_readable($path))
            throw new \InvalidArgumentException("Path $path is not readable");

        if ($standard !== Autoloader::PSR0 && $standard !== Autoloader::PSR4 && !is_callable($standard))
            throw new \InvalidArgumentException("Invalid standard: $standard");

        // Strip a leading namespace separator
        $ns = trim($ns, '\\');

        // Get the namespace parts
        $parts = explode('\\', $ns);

        $this->registered_namespaces[$ns] = true;

        // Make sure there is a trailing namespace separator
        if ($ns !== "" && substr($ns, -1, 1) !== '\\')
            $ns .= '\\';

        $ref = &$this->root_namespace;
        foreach ($parts as $part)
        {
            // Registering empty namespace
            if ($part === "")
                break;

            if (!isset($ref['sub_ns'][$part]))
                $ref['sub_ns'][$part] = ['loaders' => [], 'sub_ns' => []];

            $ref = &$ref['sub_ns'][$part];
        }

        $ref['loaders'][] = [
            'ns' => $ns,
            'path' => $path,
            'std' => $standard
        ];
    }