Skip to content

Commit

Permalink
Add trusted to most declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTheFoxgirl committed May 31, 2024
1 parent b89b9ea commit 116edd7
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 3 deletions.
1 change: 1 addition & 0 deletions source/numem/mem/exception.d
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public:
/**
Helper function to free this exception
*/
@trusted
void free() {
NuException ex = this;
nogc_delete(ex);
Expand Down
16 changes: 16 additions & 0 deletions source/numem/mem/map.d
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,21 @@ nothrow:

@disable this(this);

@trusted
~this() {
}

/// Insert an element in the container, if the container doesn't already contain
/// an element with equivalent key.
/// Returns: `true` if the insertion took place.
@trusted
bool insert(K key, V value) {
return _tree.insert(key, value);
}

/// Removes an element from the container.
/// Returns: `true` if the removal took place.
@trusted
bool remove(K key) {

// Delete memory if this map owns it.
Expand All @@ -59,26 +62,30 @@ nothrow:
}

/// Removes all elements from the map.
@trusted
void clearContents() {
nogc_delete(_tree);
// _tree reset to .init, still valid
}

/// Returns: A pointer to the value corresponding to this key, or null if not available.
/// Live builtin associative arrays.
@trusted
inout(V)* opBinaryRight(string op)(K key) inout if (op == "in") {
return key in _tree;
}

/// Returns: A reference to the value corresponding to this key.
/// Null pointer crash if key doesn't exist.
@trusted
ref inout(V) opIndex(K key) inout {
inout(V)* p = key in _tree;
assert(p !is null);
return *p;
}

/// Updates a value associated with a key, creates it if necessary.
@trusted
void opIndexAssign(V value, K key) {
V* p = key in _tree;
if (p is null) {
Expand All @@ -88,28 +95,33 @@ nothrow:
}

/// Returns: `true` if this key is contained.
@trusted
bool contains(K key) const {
return _tree.contains(key);
}

/// Returns: Number of elements in the map.
@trusted
size_t length() const {
return _tree.length;
}

/// Returns: `ttue` is the map has no element.
@trusted
bool empty() const {
return _tree.empty;
}

// Iterate by value only

/// Fetch a forward range on all values.
@trusted
auto byValue() {
return _tree.byValue();
}

/// ditto
@trusted
auto byValue() const {
return _tree.byValue();
}
Expand All @@ -120,21 +132,25 @@ nothrow:
// Iterate by key only

/// Fetch a forward range on all keys.
@trusted
auto byKey() {
return _tree.byKey();
}

/// ditto
@trusted
auto byKey() const {
return _tree.byKey();
}

// Iterate by key-value
@trusted
auto byKeyValue() {
return _tree.byKeyValue();
}

/// ditto
@trusted
auto byKeyValue() const {
return _tree.byKeyValue();
}
Expand Down
12 changes: 12 additions & 0 deletions source/numem/mem/set.d
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,29 @@ public:
nothrow:
@nogc:

@trusted
this(int dummy) {
}

@disable this(this);

@trusted
~this() {
}

/// Insert an element in the container.
/// If allowDuplicates is false, this can fail and return `false`
/// if the already contains an element with equivalent key.
/// Returns: `true` if the insertion took place.
@trusted
bool insert(K key) {
ubyte whatever = 0;
return _tree.insert(key, whatever);
}

/// Removes an element from the container.
/// Returns: `true` if the removal took place.
@trusted
bool remove(K key) {

// Delete memory if this map owns it.
Expand All @@ -63,44 +67,52 @@ nothrow:
}

/// Removes all elements from the set.
@trusted
void clearContents() {
nogc_delete(_tree);
// _tree reset to .init, still valid
}

/// Returns: `true` if the element is present.
@trusted
bool opBinaryRight(string op)(K key) inout if (op == "in") {
return (key in _tree) !is null;
}

/// Returns: `true` if the element is present.
@trusted
bool opIndex(K key) const {
return (key in _tree) !is null;
}

/// Returns: `true` if the element is present.
@trusted
bool contains(K key) const {
return (key in _tree) !is null;
}

/// Returns: Number of elements in the set.
@trusted
size_t length() const {
return _tree.length();
}

/// Returns: `ttue` is the set has no element.
@trusted
bool empty() const {
return _tree.empty();
}

// Iterate by value only

/// Fetch a forward range on all keys.
@trusted
auto byKey() {
return _tree.byKey();
}

/// ditto
@trusted
auto byKey() const {
return _tree.byKey();
}
Expand Down
Loading

0 comments on commit 116edd7

Please sign in to comment.