> For the complete documentation index, see [llms.txt](https://vala.gitbook.io/vala/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vala.gitbook.io/vala/advanced-features/collections/hashset.md).

# HashSet\<G>

Реализует: Iterable\<G>, Collection\<G>, Set\<G>

Набор из элементов типа G. Дубликаты выявляются через вычисление хэш каждого ключа, что можно настроить через передачу указателей на функции хэширования и проверки равенства ключей нужным вам способом.

Вы можете получить вид коллекции только для чтения через свойство read\_only\_view, напр. `my_map.read_only_view`. Оно вернет вам оболочку, которая будет иметь тот же интерфейс, что и коллекция внутри, но без возможности модифицировать данную коллекцию.

### Когда использовать

Эта реализация лучше подходит для сильно разнородных значений. В случае высокого значения избыточности хэшей или большого количества данных предпочтение [отдается](https://valadoc.org/gee-0.8/Gee.TreeSet.html) реализации дерева, такой как [TreeSet](https://valadoc.org/gee-0.8/Gee.TreeSet.html) .

### Set Example <a href="#set_example" id="set_example"></a>

Sets are unordered and do not contain duplicate elements.

```csharp
using Gee;

void main () {
    var my_set = new HashSet<string> ();
    my_set.add ("one");
    my_set.add ("two");
    my_set.add ("three");
    my_set.add ("two");         // will not be added because it's a duplicate
    foreach (string s in my_set) {
        stdout.printf ("%s\n", s);
    }
}
```

#### Compile and Run <a href="#compile_and_run-1" id="compile_and_run-1"></a>

```
$ valac --pkg gee-0.8 gee-set.vala
$ ./gee-set
```

### Content:

#### Properties:

* public [EqualDataFunc](https://valadoc.org/gee-0.8/Gee.EqualDataFunc.html)<[G](https://valadoc.org/gee-0.8/Gee.HashSet.G.html)> [**equal\_func**](https://valadoc.org/gee-0.8/Gee.HashSet.equal_func.html) { get; }The elements' equality testing function.
* public [HashDataFunc](https://valadoc.org/gee-0.8/Gee.HashDataFunc.html)<[G](https://valadoc.org/gee-0.8/Gee.HashSet.G.html)> [**hash\_func**](https://valadoc.org/gee-0.8/Gee.HashSet.hash_func.html) { get; }The elements' hash function.
* public override [bool](https://valadoc.org/glib-2.0/bool.html) [**read\_only**](https://valadoc.org/gee-0.8/Gee.HashSet.read_only.html) { get; }
* public override [int](https://valadoc.org/glib-2.0/int.html) [**size**](https://valadoc.org/gee-0.8/Gee.HashSet.size.html) { get; }

#### Creation methods:

* public [**HashSet**](https://valadoc.org/gee-0.8/Gee.HashSet.HashSet.html) (owned [HashDataFunc](https://valadoc.org/gee-0.8/Gee.HashDataFunc.html)<[G](https://valadoc.org/gee-0.8/Gee.HashSet.G.html)>? hash\_func = null, owned [EqualDataFunc](https://valadoc.org/gee-0.8/Gee.EqualDataFunc.html)<[G](https://valadoc.org/gee-0.8/Gee.HashSet.G.html)>? equal\_func = null)\
  Constructs a new, empty hash set.

#### Methods:

* public override [bool](https://valadoc.org/glib-2.0/bool.html) [**@foreach**](https://valadoc.org/gee-0.8/Gee.HashSet.@foreach.html) ([ForallFunc](https://valadoc.org/gee-0.8/Gee.ForallFunc.html)<[G](https://valadoc.org/gee-0.8/Gee.HashSet.G.html)> f)
* public override [bool](https://valadoc.org/glib-2.0/bool.html) [**add**](https://valadoc.org/gee-0.8/Gee.HashSet.add.html) ([G](https://valadoc.org/gee-0.8/Gee.HashSet.G.html) key)
* public override void [**clear**](https://valadoc.org/gee-0.8/Gee.HashSet.clear.html) ()
* public override [bool](https://valadoc.org/glib-2.0/bool.html) [**contains**](https://valadoc.org/gee-0.8/Gee.HashSet.contains.html) ([G](https://valadoc.org/gee-0.8/Gee.HashSet.G.html) key)
* public override [Iterator](https://valadoc.org/gee-0.8/Gee.Iterator.html)<[G](https://valadoc.org/gee-0.8/Gee.HashSet.G.html)> [**iterator**](https://valadoc.org/gee-0.8/Gee.HashSet.iterator.html) ()
* public override [bool](https://valadoc.org/glib-2.0/bool.html) [**remove**](https://valadoc.org/gee-0.8/Gee.HashSet.remove.html) ([G](https://valadoc.org/gee-0.8/Gee.HashSet.G.html) key)

### &#x20;<a href="#set_example" id="set_example"></a>

Полный список коллекций см [здесь](https://valadoc.org/gee-0.8/index.htm).&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://vala.gitbook.io/vala/advanced-features/collections/hashset.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
