Skip to content

Commit

Permalink
Merge pull request #113 from kzrnm/feature/span_segtree
Browse files Browse the repository at this point in the history
 Create Segtree<T> from Span
  • Loading branch information
kzrnm authored Dec 3, 2023
2 parents 8a68f67 + bb73844 commit 1a90668
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.8.0] - 2023-12-03
### Added
- Create `Segtree<T>` from Span

## [3.7.0] - 2023-11-29
### Added
- Add PriorityQueue.TryPeek(out T)
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<RepositoryUrl>https://github.com/kzrnm/ac-library-csharp</RepositoryUrl>
<PackageReleaseNotes>https://github.com/kzrnm/ac-library-csharp/blob/main/CHANGELOG.md</PackageReleaseNotes>

<Version>3.7.0</Version>
<AssemblyVersion>3.7.0.101</AssemblyVersion>
<Version>3.8.0</Version>
<AssemblyVersion>3.8.0.101</AssemblyVersion>
<RepositoryCommit Condition="'$(GIT_COMMIT)' != ''">$(GIT_COMMIT)</RepositoryCommit>

<SignAssembly>True</SignAssembly>
Expand Down
24 changes: 22 additions & 2 deletions Source/ac-library-csharp/DataStructure/LazySegtree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,29 @@ public LazySegtree(int n)
/// <para>計算量: O(<paramref name="n"/>)</para>
/// </remarks>
/// <param name="v">初期配列</param>
public LazySegtree(TValue[] v) : this(v.Length)
public LazySegtree(TValue[] v) : this((ReadOnlySpan<TValue>)v) { }

/// <summary>
/// 長さ n=<paramref name="v"/>.Length の数列 a を持つ <see cref="LazySegtree{TValue, F, TOp}"/> クラスの新しいインスタンスを作ります。初期値は <paramref name="v"/> です。
/// </summary>
/// <remarks>
/// <para>制約: 0≤<paramref name="n"/>≤10^8</para>
/// <para>計算量: O(<paramref name="n"/>)</para>
/// </remarks>
/// <param name="v">初期配列</param>
public LazySegtree(Span<TValue> v) : this((ReadOnlySpan<TValue>)v) { }

/// <summary>
/// 長さ n=<paramref name="v"/>.Length の数列 a を持つ <see cref="LazySegtree{TValue, F, TOp}"/> クラスの新しいインスタンスを作ります。初期値は <paramref name="v"/> です。
/// </summary>
/// <remarks>
/// <para>制約: 0≤<paramref name="n"/>≤10^8</para>
/// <para>計算量: O(<paramref name="n"/>)</para>
/// </remarks>
/// <param name="v">初期配列</param>
public LazySegtree(ReadOnlySpan<TValue> v) : this(v.Length)
{
for (int i = 0; i < v.Length; i++) d[size + i] = v[i];
v.CopyTo(d.AsSpan(size));
for (int i = size - 1; i >= 1; i--)
{
Update(i);
Expand Down
22 changes: 20 additions & 2 deletions Source/ac-library-csharp/DataStructure/Segtree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,27 @@ public Segtree(int n)
/// <para>計算量: O(<paramref name="n"/>)</para>
/// </remarks>
/// <param name="v">初期配列</param>
public Segtree(TValue[] v) : this(v.Length)
public Segtree(TValue[] v) : this((ReadOnlySpan<TValue>)v) { }
/// <summary>
/// 長さ n=<paramref name="v"/>.Length の数列 a を持つ <see cref="Segtree{TValue, TOp}"/> クラスの新しいインスタンスを作ります。初期値は <paramref name="v"/> です。
/// </summary>
/// <remarks>
/// <para>制約: 0≤<paramref name="n"/>≤10^8</para>
/// <para>計算量: O(<paramref name="n"/>)</para>
/// </remarks>
/// <param name="v">初期配列</param>
public Segtree(Span<TValue> v) : this((ReadOnlySpan<TValue>)v) { }
/// <summary>
/// 長さ n=<paramref name="v"/>.Length の数列 a を持つ <see cref="Segtree{TValue, TOp}"/> クラスの新しいインスタンスを作ります。初期値は <paramref name="v"/> です。
/// </summary>
/// <remarks>
/// <para>制約: 0≤<paramref name="n"/>≤10^8</para>
/// <para>計算量: O(<paramref name="n"/>)</para>
/// </remarks>
/// <param name="v">初期配列</param>
public Segtree(ReadOnlySpan<TValue> v) : this(v.Length)
{
for (int i = 0; i < v.Length; i++) d[size + i] = v[i];
v.CopyTo(d.AsSpan(size));
for (int i = size - 1; i >= 1; i--)
{
Update(i);
Expand Down

0 comments on commit 1a90668

Please sign in to comment.