Web Analytics

bwarr

⭐ 116 stars Korean by dronnix

이것은 무엇인가?

CI codecov Go Reference Go Report Card

블랙-화이트 배열(또는 BWArr)은 $O(\log N)$ 메모리 할당을 기반으로 하는 빠르고 정렬된 배열 기반 데이터 구조입니다.

데이터 구조

블랙-화이트 배열의 아이디어는 교수 Z. George Mou에 의해 고안되어 Black-White Array: A New Data Structure for Dynamic Data Sets 논문에서 발표되었습니다. 이 저장소는 최초의 공개 구현체를 포함합니다.

교수 Z. George Mou

주요 특징:

트레이드오프

벤치마크

Google BTree와 비교한 벤치마크입니다.

#### 삽입 빈 데이터 구조에 N개의 고유한 임의 int64 값을 삽입하는 데 걸리는 시간, 할당 수 및 할당된 KB 수를 측정합니다. BWArr와 BTree 모두 빈 상태에서 시작하여 모든 값을 하나씩 삽입합니다.

삽입 성능 삽입 할당 삽입 할당_바이트 작은 값에 대한 할당:

Insert Allocs small

#### Get 미리 채워진 데이터 구조에서 키로 N개의 값을 조회하는 데 걸리는 시간을 측정합니다. 데이터 구조는 타이밍이 시작되기 전에 모든 값으로 채워지고, 각 값은 키로 검색됩니다.

Get performance

#### Iterate 정렬된 순서와 정렬되지 않은 순서로 모든 N개의 값을 반복하는 데 걸리는 시간을 측정합니다. Ordered Iterate performance Unordered Iterate performance

#### 추가 벤치마크 추가 벤치마크 및 세부 정보는 bwarr-bench 저장소에서 확인할 수 있습니다. 더 많은 메서드가 추가될 예정이며, AMD64 및 ARM64 아키텍처별 별도 벤치마크도 기대할 수 있습니다.

설치

Go 1.22 이상이 필요합니다.

go get github.com/dronnix/bwarr

그런 다음 코드에서 가져오십시오:

import "github.com/dronnix/bwarr"

사용법

기본 예제

package main

import ( "fmt"

"github.com/dronnix/bwarr" )

func main() { // Create a BWArr with an integer comparison function // The second parameter (10) is the initial capacity hint bwa := bwarr.New(func(a, b int64) int { return int(a - b) }, 10)

// Insert elements bwa.Insert(42) bwa.Insert(17) bwa.Insert(99) bwa.Insert(23) bwa.Insert(8)

fmt.Printf("Length: %d\n", bwa.Len()) // Output: Length: 5

// Get an element val, found := bwa.Get(42) if found { fmt.Printf("Found: %d\n", val) // Output: Found: 42 }

// Delete an element deleted, found := bwa.Delete(17) if found { fmt.Printf("Deleted: %d\n", deleted) // Output: Deleted: 17 }

// Iterate in ascending order fmt.Println("Elements in sorted order:") bwa.Ascend(func(item int64) bool { fmt.Printf(" %d\n", item) return true // return false to stop iteration early }) // Output: // 8 // 23 // 42 // 99 }

--- Tranlated By Open Ai Tx | Last indexed: 2026-07-08 ---