From 9dc4dc19609262c2d8d0ad74b445b2eac69c8a60 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Mon, 5 Sep 2016 18:26:43 -0700 Subject: [PATCH] Add BitArray.Update() --- bit_array.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bit_array.go b/bit_array.go index 78cf840f3..5590fe61b 100644 --- a/bit_array.go +++ b/bit_array.go @@ -302,3 +302,16 @@ func (bA *BitArray) Bytes() []byte { } return bytes } + +// NOTE: other bitarray o is not locked when reading, +// so if necessary, caller must copy or lock o prior to calling Update. +// If bA is nil, does nothing. +func (bA *BitArray) Update(o *BitArray) { + if bA == nil { + return + } + bA.mtx.Lock() + defer bA.mtx.Unlock() + + copy(bA.Elems, o.Elems) +}