nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
containers.hpp
Go to the documentation of this file.
1
3// src/runtime/include/nk/runtime/containers.hpp
4//
5// Public C++ API for the key–value container objects (`containers.Map`, `dictionary`).
6#pragma once
7
8#include <nk/value/value.hpp>
9
10#include <cstddef>
11#include <memory_resource>
12
13namespace nk {
14
17
18class Engine;
19}
20
21namespace nk::runtime {
22
26
27namespace containers {
28
29// ── Constructors ─────────────────────────────────────────────
30
35Value map(std::pmr::memory_resource *mr = nullptr);
36
41Value dictionary(std::pmr::memory_resource *mr = nullptr);
42
43// ── Operations (work on either container) ────────────────────
44
49void set(Value &m, const Value &key, const Value &val);
50
56Value get(const Value &m, const Value &key);
57
63bool isKey(const Value &m, const Value &key);
64
68void remove(Value &m, const Value &key);
69
73std::size_t count(const Value &m);
74
80Value keys(const Value &m, std::pmr::memory_resource *mr = nullptr);
81
87Value values(const Value &m, std::pmr::memory_resource *mr = nullptr);
88
89} // namespace containers
90} // namespace nk::runtime
91
92namespace nk::containers {
93using namespace ::nk::runtime::containers;
94
96}
Core MATLAB-compatible multidimensional array and scalar value type.
Definition value.hpp:61
Value values(const Value &m, std::pmr::memory_resource *mr=nullptr)
Extracts all values from container as an array or cell array.
Value get(const Value &m, const Value &key)
Looks up value associated with specified key (throws if key absent).
void remove(Value &m, const Value &key)
Removes specified key and its associated value from container.
void registerContainersRuntime(Engine &engine)
Registers containers.Map and dictionary builtins in the engine.
Value map(std::pmr::memory_resource *mr=nullptr)
Creates an empty containers.Map (handle semantics: copies alias shared state).
std::size_t count(const Value &m)
Returns the number of key-value pairs in container.
void set(Value &m, const Value &key, const Value &val)
Inserts or updates key-value pair in container in place.
Value keys(const Value &m, std::pmr::memory_resource *mr=nullptr)
Extracts all keys from container as a column array.
Value dictionary(std::pmr::memory_resource *mr=nullptr)
Creates an empty dictionary (value semantics: copies are independent).
bool isKey(const Value &m, const Value &key)
Checks whether specified key exists in container.