Skip to content

Commit

Permalink
Merge pull request #234 from unum-cloud/main-dev
Browse files Browse the repository at this point in the history
Fix: nullable `cstring` function arguments
  • Loading branch information
ashvardanian authored Aug 28, 2023
2 parents 0c2c633 + f264248 commit 5b585e4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Euclidean • Angular • Bitwise • Haversine • User-Defined Metrics
<a href="https://unum-cloud.github.io/usearch/c">C 99</a> •
<a href="https://unum-cloud.github.io/usearch/objective-c">Objective-C</a> •
<a href="https://unum-cloud.github.io/usearch/swift">Swift</a> •
<a href="https://unum-cloud.github.io/usearch/csharp">C#</a> •
<a href="https://unum-cloud.github.io/usearch/golang">GoLang</a> •
<a href="https://unum-cloud.github.io/usearch/wolfram">Wolfram</a>
<br/>
Expand All @@ -38,6 +39,8 @@ Linux • MacOS • Windows • iOS • Docker • WebAssembly
<a href="https://pypi.org/project/usearch/"> <img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/usearch?label=pypi%20downloads"> </a>
<a href="https://www.npmjs.com/package/usearch"> <img alt="npm" src="https://img.shields.io/npm/dy/usearch?label=npm%20dowloads"> </a>
<a href="https://crates.io/crates/usearch"> <img alt="Crates.io" src="https://img.shields.io/crates/d/usearch?label=crate%20downloads"> </a>
<a href="https://www.nuget.org/packages/Cloud.Unum.USearch"> <img alt="Nuget" src="https://img.shields.io/nuget/dt/Cloud.Unum.USearch?style=social&label=NuGet"> </a>
<a href="https://hub.docker.com/r/unum/usearch"> <img alt="Docker Pulls" src="https://img.shields.io/docker/pulls/unum/usearch?style=social&label=Docker"> </a>
<img alt="GitHub code size in bytes" src="https://img.shields.io/github/languages/code-size/unum-cloud/usearch">
</div>

Expand Down
13 changes: 5 additions & 8 deletions csharp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
## Installation

```sh
dotnet add package Cloud.Unum.USearch -s https://apiint.nugettest.org/v3/index.json
dotnet add package Cloud.Unum.USearch
```

## Quickstart

```C#
```csharp
using System.Diagnostics;
using Cloud.Unum.USearch;

using var index = new USearchIndex(
metricKind: MetricKind.Cos, //Choose cosine metric
metricKind: MetricKind.Cos, // Choose cosine metric
quantization: ScalarKind.Float32, // Only quantization to Float32, Float64 is currently supported
dimensions: 3, // Define the number of dimensions in input vectors
connectivity: 16, // How frequent should the connections in the graph be, optional
Expand All @@ -29,14 +29,11 @@ Trace.Assert(index.Size() == 1);
Trace.Assert(matches == 1);
Trace.Assert(keys[0] == 42);
Trace.Assert(distances[0] <= 0.001f);
// USearchIndex obj created with "using statement" and implements IDisposable,
// otherwise call it explicitly:
// index.Dispose();
```

## Serialization

```C#
```csharp
index.Save("index.usearch")

// Copy the whole index into memory
Expand All @@ -55,7 +52,7 @@ Trace.Assert(indexLoaded.Contains(42));

Adding a batch of entries is identical to adding a single vector.

```C#
```csharp
using var index = new USearchIndex(MetricKind.Cos, ScalarKind.Float32, dimensions: 3);

// Generate keys and random vectors
Expand Down
6 changes: 6 additions & 0 deletions docs/csharp/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
==============
C# SDK
==============


.. mdinclude:: ../../csharp/README.md
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Overview
java/index
c/index
swift/index
csharp/index
golang/index
wolfram/index

Expand Down
8 changes: 6 additions & 2 deletions include/usearch/index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,10 @@ template <typename allocator_at = std::allocator<byte_t>> class bitset_gt {
~bitset_gt() noexcept { reset(); }

explicit operator bool() const noexcept { return slots_; }
void clear() noexcept { std::memset(slots_, 0, count_ * sizeof(compressed_slot_t)); }
void clear() noexcept {
if (slots_)
std::memset(slots_, 0, count_ * sizeof(compressed_slot_t));
}

void reset() noexcept {
if (slots_)
Expand Down Expand Up @@ -857,7 +860,8 @@ class growing_hash_set_gt {
std::size_t size() const noexcept { return count_; }

void clear() noexcept {
std::memset((void*)slots_, 0xFF, capacity_ * sizeof(element_t));
if (slots_)
std::memset((void*)slots_, 0xFF, capacity_ * sizeof(element_t));
count_ = 0;
}

Expand Down

0 comments on commit 5b585e4

Please sign in to comment.