Ruby 3.5.0dev (2025-07-15 revision 87944065838321018bf99fc61dbec84ccad2576c)
Functions
set.h File Reference

(87944065838321018bf99fc61dbec84ccad2576c)

Public APIs related to rb_cSet. More...

#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
Include dependency graph for set.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void rb_set_foreach (VALUE set, int(*func)(VALUE element, VALUE arg), VALUE arg)
 Iterates over a set.
 
VALUE rb_set_new (void)
 Creates a new, empty set object.
 
VALUE rb_set_new_capa (size_t capa)
 Identical to rb_set_new(), except it additionally specifies how many elements it is expected to contain.
 
bool rb_set_lookup (VALUE set, VALUE element)
 Whether the set contains the given element.
 
bool rb_set_add (VALUE set, VALUE element)
 Adds element to set.
 
VALUE rb_set_clear (VALUE set)
 Removes all entries from set.
 
bool rb_set_delete (VALUE set, VALUE element)
 Removes the element from from set.
 
size_t rb_set_size (VALUE set)
 Returns the number of elements in the set.
 

Detailed Description

Public APIs related to rb_cSet.

Author
Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org
Warning
Symbols prefixed with either RBIMPL or rbimpl are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.
Note
To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance __VA_ARGS__ is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.

Definition in file set.h.

Function Documentation

◆ rb_set_add()

bool rb_set_add ( VALUE  set,
VALUE  element 
)

Adds element to set.

Parameters
[in]setTarget set table to modify.
[in]elementArbitrary Ruby object.
Exceptions
rb_eFrozenError`set` is frozen.
Returns
true if element was not already in set, false otherwise
Postcondition
element is in set.

Definition at line 1943 of file set.c.

Referenced by rb_set_add().

◆ rb_set_clear()

VALUE rb_set_clear ( VALUE  set)

Removes all entries from set.

Parameters
[out]setTarget to clear.
Exceptions
rb_eFrozenError`set`is frozen.
Returns
The passed set
Postcondition
set has no elements.

Definition at line 1949 of file set.c.

Referenced by rb_set_clear().

◆ rb_set_delete()

bool rb_set_delete ( VALUE  set,
VALUE  element 
)

Removes the element from from set.

Parameters
[in]setTarget set to modify.
[in]elementKey to delete.
Return values
trueif element was already in set, false otherwise
Postcondition
set does not have element as an element.

Definition at line 1955 of file set.c.

Referenced by rb_set_delete().

◆ rb_set_foreach()

void rb_set_foreach ( VALUE  set,
int(*)(VALUE element, VALUE arg)  func,
VALUE  arg 
)

Iterates over a set.

Calls func with each element of the set and the argument given. func should return ST_CONTINUE, ST_STOP, or ST_DELETE.

Parameters
[in]setAn instance of rb_cSet to iterate over.
[in]funcCallback function to yield.
[in]argPassed as-is to func.
Exceptions
rb_eRuntimeError`set` was tampered during iterating.

Definition at line 1919 of file set.c.

Referenced by rb_set_foreach().

◆ rb_set_lookup()

bool rb_set_lookup ( VALUE  set,
VALUE  element 
)

Whether the set contains the given element.

Parameters
[in]setSet to look into.
[in]elementSet element to look for.
Returns
true if element is in the set, falst otherwise.

Definition at line 1937 of file set.c.

Referenced by rb_set_lookup().

◆ rb_set_new()

VALUE rb_set_new ( void  )

Creates a new, empty set object.

Returns
An allocated new instance of rb_cSet.

Definition at line 1925 of file set.c.

Referenced by rb_set_new().

◆ rb_set_new_capa()

VALUE rb_set_new_capa ( size_t  capa)

Identical to rb_set_new(), except it additionally specifies how many elements it is expected to contain.

This way you can create a set that is large enough for your need. For large sets, it means it won't need to be reallocated much, improving performance.

Parameters
[in]capaDesigned capacity of the set.
Returns
An empty Set, whose capacity is capa.

Definition at line 1931 of file set.c.

Referenced by rb_set_new_capa().

◆ rb_set_size()

size_t rb_set_size ( VALUE  set)

Returns the number of elements in the set.

Parameters
[in]setA set object.
Returns
The size of the set.

Definition at line 1961 of file set.c.

Referenced by rb_set_size().