github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/base/bslice/any.go (about) 1 package bslice 2 3 import ( 4 "encoding/json" 5 "errors" 6 "fmt" 7 "sync" 8 9 "github.com/songzhibin97/go-baseutils/base/bcomparator" 10 ) 11 12 // ===================================================================================================================== 13 // unsafe 14 15 func NewUnsafeAnyBSlice[E any]() *UnsafeAnyBSlice[E] { 16 return &UnsafeAnyBSlice[E]{ 17 e: []E{}, 18 } 19 } 20 21 func NewUnsafeAnyBSliceBySlice[E any](s []E) *UnsafeAnyBSlice[E] { 22 return &UnsafeAnyBSlice[E]{ 23 e: s, 24 } 25 } 26 27 type UnsafeAnyBSlice[E any] struct { 28 e []E 29 zero E 30 } 31 32 func (x *UnsafeAnyBSlice[E]) EqualFunc(es []E, f func(E, E) bool) bool { 33 return EqualFunc(x.e, es, f) 34 } 35 36 func (x *UnsafeAnyBSlice[E]) CompareFunc(es []E, f func(E, E) int) int { 37 return CompareFunc(x.e, es, f) 38 } 39 40 func (x *UnsafeAnyBSlice[E]) IndexFunc(f func(E) bool) int { 41 return IndexFunc(x.e, f) 42 } 43 44 func (x *UnsafeAnyBSlice[E]) Insert(i int, e ...E) { 45 _ = x.InsertE(i, e...) 46 } 47 48 func (x *UnsafeAnyBSlice[E]) InsertE(i int, e ...E) error { 49 if i < 0 || i > len(x.e) { 50 return errors.New("insert index out of range") 51 } 52 x.e = Insert(x.e, i, e...) 53 return nil 54 } 55 56 func (x *UnsafeAnyBSlice[E]) Delete(i int, j int) { 57 _ = x.DeleteE(i, j) 58 } 59 60 func (x *UnsafeAnyBSlice[E]) DeleteE(i int, j int) error { 61 ln := len(x.e) 62 if ln == 0 { 63 return nil 64 } 65 if i < 0 || j > ln || i > j { 66 return errors.New(fmt.Sprintf("invalid range:%d-%d, ln:%d", i, j, ln)) 67 } 68 x.e = Delete(x.e, i, j) 69 return nil 70 } 71 72 func (x *UnsafeAnyBSlice[E]) DeleteToSlice(i int, j int) []E { 73 v, _ := x.DeleteToSliceE(i, j) 74 return v 75 } 76 77 func (x *UnsafeAnyBSlice[E]) DeleteToSliceE(i int, j int) ([]E, error) { 78 ln := len(x.e) 79 if ln == 0 { 80 return nil, nil 81 } 82 if i < 0 || j > ln || i > j { 83 return nil, errors.New(fmt.Sprintf("invalid range:%d-%d, ln:%d", i, j, ln)) 84 } 85 return Delete(x.e, i, j), nil 86 } 87 88 func (x *UnsafeAnyBSlice[E]) DeleteToBSlice(i int, j int) AnyBSlice[E] { 89 v, err := x.DeleteToBSliceE(i, j) 90 if err != nil { 91 return v 92 } 93 return v 94 } 95 96 func (x *UnsafeAnyBSlice[E]) DeleteToBSliceE(i int, j int) (AnyBSlice[E], error) { 97 ln := len(x.e) 98 if ln == 0 { 99 return NewUnsafeAnyBSlice[E](), nil 100 } 101 if i < 0 || j > ln || i > j { 102 return NewUnsafeAnyBSlice[E](), errors.New(fmt.Sprintf("invalid range:%d-%d, ln:%d", i, j, ln)) 103 } 104 return NewUnsafeAnyBSliceBySlice(Delete(x.e, i, j)), nil 105 } 106 107 func (x *UnsafeAnyBSlice[E]) Replace(i int, j int, e ...E) { 108 _ = x.ReplaceE(i, j, e...) 109 } 110 111 func (x *UnsafeAnyBSlice[E]) ReplaceE(i int, j int, e ...E) error { 112 ln := len(x.e) 113 if i < 0 || j > ln || i > j { 114 return errors.New(fmt.Sprintf("invalid range:%d-%d, ln:%d", i, j, ln)) 115 } 116 x.e = Replace(x.e, i, j, e...) 117 return nil 118 } 119 120 func (x *UnsafeAnyBSlice[E]) CloneToSlice() []E { 121 return Clone(x.e) 122 } 123 124 func (x *UnsafeAnyBSlice[E]) CloneToBSlice() AnyBSlice[E] { 125 return NewUnsafeAnyBSliceBySlice(Clone(x.e)) 126 } 127 128 func (x *UnsafeAnyBSlice[E]) CompactFunc(f func(E, E) bool) { 129 x.e = CompactFunc(x.e, f) 130 } 131 132 func (x *UnsafeAnyBSlice[E]) Grow(i int) { 133 _ = x.GrowE(i) 134 } 135 136 func (x *UnsafeAnyBSlice[E]) GrowE(i int) error { 137 if i < 0 { 138 return errors.New("insert index out of range") 139 } 140 x.e = Grow(x.e, i) 141 return nil 142 } 143 144 func (x *UnsafeAnyBSlice[E]) Clip() { 145 x.e = Clip(x.e) 146 } 147 148 func (x *UnsafeAnyBSlice[E]) ForEach(f func(int, E)) { 149 for i, e := range x.e { 150 f(i, e) 151 } 152 } 153 154 func (x *UnsafeAnyBSlice[E]) SortFunc(f func(i E, j E) bool) { 155 SortFunc(x.e, f) 156 } 157 158 func (x *UnsafeAnyBSlice[E]) SortFuncToSlice(f func(i E, j E) bool) []E { 159 es := x.e 160 cp := make([]E, len(es)) 161 copy(cp, es) 162 SortFunc(cp, f) 163 return cp 164 } 165 166 func (x *UnsafeAnyBSlice[E]) SortFuncToBSlice(f func(i E, j E) bool) AnyBSlice[E] { 167 es := x.e 168 cp := make([]E, len(es)) 169 copy(cp, es) 170 SortFunc(cp, f) 171 return NewUnsafeAnyBSliceBySlice(cp) 172 } 173 174 func (x *UnsafeAnyBSlice[E]) SortComparator(f bcomparator.Comparator[E]) { 175 bcomparator.Sort(x.e, f) 176 } 177 178 func (x *UnsafeAnyBSlice[E]) SortComparatorToSlice(f bcomparator.Comparator[E]) []E { 179 es := x.e 180 cp := make([]E, len(es)) 181 copy(cp, es) 182 bcomparator.Sort(cp, f) 183 return cp 184 } 185 186 func (x *UnsafeAnyBSlice[E]) SortComparatorToBSlice(f bcomparator.Comparator[E]) AnyBSlice[E] { 187 es := x.e 188 cp := make([]E, len(es)) 189 copy(cp, es) 190 bcomparator.Sort(cp, f) 191 return NewUnsafeAnyBSliceBySlice(cp) 192 } 193 194 func (x *UnsafeAnyBSlice[E]) SortStableFunc(f func(i E, j E) bool) { 195 SortStableFunc(x.e, f) 196 } 197 198 func (x *UnsafeAnyBSlice[E]) SortStableFuncToSlice(f func(i E, j E) bool) []E { 199 es := x.e 200 cp := make([]E, len(es)) 201 copy(cp, es) 202 SortStableFunc(cp, f) 203 return cp 204 } 205 206 func (x *UnsafeAnyBSlice[E]) SortStableFuncToBSlice(f func(i E, j E) bool) AnyBSlice[E] { 207 es := x.e 208 cp := make([]E, len(es)) 209 copy(cp, es) 210 SortStableFunc(cp, f) 211 return NewUnsafeAnyBSliceBySlice(cp) 212 } 213 214 func (x *UnsafeAnyBSlice[E]) IsSortedFunc(f func(i E, j E) bool) bool { 215 return IsSortedFunc(x.e, f) 216 } 217 218 func (x *UnsafeAnyBSlice[E]) BinarySearchFunc(e E, f func(E, E) int) (int, bool) { 219 return BinarySearchFunc(x.e, e, f) 220 } 221 222 func (x *UnsafeAnyBSlice[E]) Filter(f func(E) bool) { 223 var res []E 224 for _, e := range x.e { 225 if f(e) { 226 res = append(res, e) 227 } 228 } 229 x.e = res 230 } 231 232 func (x *UnsafeAnyBSlice[E]) FilterToSlice(f func(E) bool) []E { 233 var res []E 234 for _, e := range x.e { 235 if f(e) { 236 res = append(res, e) 237 } 238 } 239 return res 240 } 241 242 func (x *UnsafeAnyBSlice[E]) FilterToBSlice(f func(E) bool) AnyBSlice[E] { 243 var res []E 244 for _, e := range x.e { 245 if f(e) { 246 res = append(res, e) 247 } 248 } 249 return NewUnsafeAnyBSliceBySlice(res) 250 } 251 252 func (x *UnsafeAnyBSlice[E]) Reverse() { 253 l, r := 0, len(x.e)-1 254 for l < r { 255 x.e[l], x.e[r] = x.e[r], x.e[l] 256 l++ 257 r-- 258 } 259 } 260 261 func (x *UnsafeAnyBSlice[E]) ReverseToSlice() []E { 262 es := x.e 263 cp := make([]E, len(es)) 264 copy(cp, es) 265 l, r := 0, len(cp)-1 266 for l < r { 267 cp[l], cp[r] = cp[r], cp[l] 268 l++ 269 r-- 270 } 271 return cp 272 } 273 274 func (x *UnsafeAnyBSlice[E]) ReverseToBSlice() AnyBSlice[E] { 275 es := x.e 276 cp := make([]E, len(es)) 277 copy(cp, es) 278 l, r := 0, len(cp)-1 279 for l < r { 280 cp[l], cp[r] = cp[r], cp[l] 281 l++ 282 r-- 283 } 284 return NewUnsafeAnyBSliceBySlice(cp) 285 } 286 287 func (x *UnsafeAnyBSlice[E]) Marshal() ([]byte, error) { 288 if x.e == nil { 289 return []byte("[]"), nil 290 } 291 return json.Marshal(x.e) 292 } 293 294 func (x *UnsafeAnyBSlice[E]) Unmarshal(data []byte) error { 295 if x.e == nil { 296 x.e = []E{} 297 } 298 return json.Unmarshal(data, &x.e) 299 } 300 301 func (x *UnsafeAnyBSlice[E]) Len() int { 302 return len(x.e) 303 } 304 305 func (x *UnsafeAnyBSlice[E]) Cap() int { 306 return cap(x.e) 307 } 308 309 func (x *UnsafeAnyBSlice[E]) ToInterfaceSlice() []interface{} { 310 res := make([]interface{}, len(x.e)) 311 for i, e := range x.e { 312 res[i] = e 313 } 314 return res 315 } 316 317 func (x *UnsafeAnyBSlice[E]) ToMetaSlice() []E { 318 return x.e 319 } 320 321 func (x *UnsafeAnyBSlice[E]) Swap(i, j int) { 322 ln := len(x.e) 323 if i < 0 || j < 0 || i >= ln || j >= ln || i == j { 324 return 325 } 326 x.e[i], x.e[j] = x.e[j], x.e[i] 327 } 328 329 func (x *UnsafeAnyBSlice[E]) Clear() { 330 x.e = []E{} 331 } 332 333 func (x *UnsafeAnyBSlice[E]) Append(es ...E) { 334 x.e = append(x.e, es...) 335 } 336 337 func (x *UnsafeAnyBSlice[E]) AppendToSlice(es ...E) []E { 338 nes := x.e 339 cp := make([]E, len(nes)) 340 copy(cp, nes) 341 return append(cp, es...) 342 } 343 344 func (x *UnsafeAnyBSlice[E]) AppendToBSlice(es ...E) AnyBSlice[E] { 345 nes := x.e 346 cp := make([]E, len(nes)) 347 copy(cp, nes) 348 return NewUnsafeAnyBSliceBySlice(append(cp, es...)) 349 } 350 351 func (x *UnsafeAnyBSlice[E]) CopyToSlice() []E { 352 nes := x.e 353 cp := make([]E, len(nes)) 354 copy(cp, nes) 355 return cp 356 } 357 358 func (x *UnsafeAnyBSlice[E]) CopyToBSlice() AnyBSlice[E] { 359 nes := x.e 360 cp := make([]E, len(nes)) 361 copy(cp, nes) 362 return NewUnsafeAnyBSliceBySlice(cp) 363 } 364 365 func (x *UnsafeAnyBSlice[E]) GetByIndex(index int) E { 366 v, _ := x.GetByIndexE(index) 367 return v 368 } 369 370 func (x *UnsafeAnyBSlice[E]) GetByIndexE(index int) (E, error) { 371 if index < 0 || index >= len(x.e) { 372 return x.zero, errors.New("index out of range") 373 } 374 return x.e[index], nil 375 } 376 377 func (x *UnsafeAnyBSlice[E]) GetByIndexOrDefault(index int, defaultE E) E { 378 if index < 0 || index >= len(x.e) { 379 return defaultE 380 } 381 return x.e[index] 382 } 383 384 func (x *UnsafeAnyBSlice[E]) GetByRange(start int, end int) []E { 385 v, _ := x.GetByRangeE(start, end) 386 return v 387 } 388 389 func (x *UnsafeAnyBSlice[E]) GetByRangeE(start int, end int) ([]E, error) { 390 ln := len(x.e) 391 if start < 0 || end > ln || start > end { 392 return nil, errors.New(fmt.Sprintf("invalid range:%d-%d, ln:%d", start, end, ln)) 393 } 394 v := x.e[start:end] 395 cp := make([]E, len(v)) 396 copy(cp, v) 397 return v, nil 398 } 399 400 func (x *UnsafeAnyBSlice[E]) SetByIndex(index int, e E) { 401 _ = x.SetByIndexE(index, e) 402 403 } 404 405 func (x *UnsafeAnyBSlice[E]) SetByIndexE(index int, e E) error { 406 if index < 0 || index >= len(x.e) { 407 return errors.New("index out of range") 408 } 409 x.e[index] = e 410 return nil 411 } 412 413 func (x *UnsafeAnyBSlice[E]) SetByRange(index int, es []E) { 414 _ = x.SetByRangeE(index, es) 415 } 416 417 func (x *UnsafeAnyBSlice[E]) SetByRangeE(index int, es []E) error { 418 if index < 0 { 419 return errors.New("insert index out of range") 420 } 421 total := index + len(es) 422 if total > cap(x.e) { 423 x.Append(es...) 424 return nil 425 } 426 copy(x.e[index:total], es) 427 return nil 428 } 429 430 // ===================================================================================================================== 431 // safe 432 433 func NewSafeAnyBSlice[E any]() *SafeAnyBSlice[E] { 434 return &SafeAnyBSlice[E]{ 435 es: NewUnsafeAnyBSlice[E](), 436 } 437 } 438 439 func NewSafeAnyBSliceBySlice[E any](e []E) *SafeAnyBSlice[E] { 440 return &SafeAnyBSlice[E]{ 441 es: NewUnsafeAnyBSliceBySlice(e), 442 } 443 } 444 445 type SafeAnyBSlice[E any] struct { 446 es *UnsafeAnyBSlice[E] 447 rwl sync.RWMutex 448 } 449 450 func (x *SafeAnyBSlice[E]) Marshal() ([]byte, error) { 451 x.rwl.RLock() 452 defer x.rwl.RUnlock() 453 return x.es.Marshal() 454 } 455 456 func (x *SafeAnyBSlice[E]) Unmarshal(data []byte) error { 457 x.rwl.Lock() 458 defer x.rwl.Unlock() 459 return x.es.Unmarshal(data) 460 } 461 462 func (x *SafeAnyBSlice[E]) Len() int { 463 x.rwl.RLock() 464 defer x.rwl.RUnlock() 465 return x.es.Len() 466 } 467 468 func (x *SafeAnyBSlice[E]) Cap() int { 469 x.rwl.RLock() 470 defer x.rwl.RUnlock() 471 return x.es.Cap() 472 } 473 474 func (x *SafeAnyBSlice[E]) ToInterfaceSlice() []interface{} { 475 x.rwl.RLock() 476 defer x.rwl.RUnlock() 477 return x.es.ToInterfaceSlice() 478 } 479 480 func (x *SafeAnyBSlice[E]) Swap(i, j int) { 481 x.rwl.Lock() 482 defer x.rwl.Unlock() 483 x.es.Swap(i, j) 484 } 485 486 func (x *SafeAnyBSlice[E]) Clear() { 487 x.rwl.Lock() 488 defer x.rwl.Unlock() 489 x.es.Clear() 490 } 491 492 func (x *SafeAnyBSlice[E]) EqualFunc(es []E, f func(E, E) bool) bool { 493 x.rwl.RLock() 494 defer x.rwl.RUnlock() 495 return x.es.EqualFunc(es, f) 496 } 497 498 func (x *SafeAnyBSlice[E]) CompareFunc(es []E, f func(E, E) int) int { 499 x.rwl.RLock() 500 defer x.rwl.RUnlock() 501 return x.es.CompareFunc(es, f) 502 } 503 504 func (x *SafeAnyBSlice[E]) IndexFunc(f func(E) bool) int { 505 x.rwl.RLock() 506 defer x.rwl.RUnlock() 507 return x.es.IndexFunc(f) 508 } 509 510 func (x *SafeAnyBSlice[E]) Insert(i int, e ...E) { 511 x.rwl.Lock() 512 defer x.rwl.Unlock() 513 x.es.Insert(i, e...) 514 } 515 516 func (x *SafeAnyBSlice[E]) InsertE(i int, e ...E) error { 517 x.rwl.Lock() 518 defer x.rwl.Unlock() 519 return x.es.InsertE(i, e...) 520 } 521 522 func (x *SafeAnyBSlice[E]) Delete(i int, i2 int) { 523 x.rwl.Lock() 524 defer x.rwl.Unlock() 525 x.es.Delete(i, i2) 526 } 527 528 func (x *SafeAnyBSlice[E]) DeleteE(i int, i2 int) error { 529 x.rwl.Lock() 530 defer x.rwl.Unlock() 531 return x.es.DeleteE(i, i2) 532 } 533 534 func (x *SafeAnyBSlice[E]) DeleteToSlice(i int, i2 int) []E { 535 x.rwl.Lock() 536 defer x.rwl.Unlock() 537 return x.es.DeleteToSlice(i, i2) 538 } 539 540 func (x *SafeAnyBSlice[E]) DeleteToSliceE(i int, i2 int) ([]E, error) { 541 x.rwl.Lock() 542 defer x.rwl.Unlock() 543 return x.es.DeleteToSliceE(i, i2) 544 } 545 546 func (x *SafeAnyBSlice[E]) DeleteToBSlice(i int, i2 int) AnyBSlice[E] { 547 x.rwl.Lock() 548 defer x.rwl.Unlock() 549 return x.es.DeleteToBSlice(i, i2) 550 } 551 552 func (x *SafeAnyBSlice[E]) DeleteToBSliceE(i int, i2 int) (AnyBSlice[E], error) { 553 x.rwl.Lock() 554 defer x.rwl.Unlock() 555 return x.es.DeleteToBSliceE(i, i2) 556 } 557 558 func (x *SafeAnyBSlice[E]) Replace(i int, i2 int, e ...E) { 559 x.rwl.Lock() 560 defer x.rwl.Unlock() 561 x.es.Replace(i, i2, e...) 562 } 563 564 func (x *SafeAnyBSlice[E]) ReplaceE(i int, i2 int, e ...E) error { 565 x.rwl.Lock() 566 defer x.rwl.Unlock() 567 return x.es.ReplaceE(i, i2, e...) 568 } 569 570 func (x *SafeAnyBSlice[E]) CloneToSlice() []E { 571 x.rwl.RLock() 572 defer x.rwl.RUnlock() 573 return x.es.CloneToSlice() 574 } 575 576 func (x *SafeAnyBSlice[E]) CloneToBSlice() AnyBSlice[E] { 577 x.rwl.RLock() 578 defer x.rwl.RUnlock() 579 return x.es.CloneToBSlice() 580 } 581 582 func (x *SafeAnyBSlice[E]) CompactFunc(f func(E, E) bool) { 583 x.rwl.Lock() 584 defer x.rwl.Unlock() 585 x.es.CompactFunc(f) 586 } 587 588 func (x *SafeAnyBSlice[E]) Grow(i int) { 589 x.rwl.Lock() 590 defer x.rwl.Unlock() 591 x.es.Grow(i) 592 } 593 594 func (x *SafeAnyBSlice[E]) GrowE(i int) error { 595 x.rwl.Lock() 596 defer x.rwl.Unlock() 597 return x.es.GrowE(i) 598 } 599 600 func (x *SafeAnyBSlice[E]) Clip() { 601 x.rwl.Lock() 602 defer x.rwl.Unlock() 603 x.es.Clip() 604 } 605 606 func (x *SafeAnyBSlice[E]) ForEach(f func(int, E)) { 607 x.rwl.RLock() 608 defer x.rwl.RUnlock() 609 x.es.ForEach(f) 610 } 611 612 func (x *SafeAnyBSlice[E]) SortFunc(f func(i E, j E) bool) { 613 x.rwl.Lock() 614 defer x.rwl.Unlock() 615 x.es.SortFunc(f) 616 } 617 618 func (x *SafeAnyBSlice[E]) SortFuncToSlice(f func(i E, j E) bool) []E { 619 x.rwl.RLock() 620 defer x.rwl.RUnlock() 621 return x.es.SortFuncToSlice(f) 622 } 623 624 func (x *SafeAnyBSlice[E]) SortFuncToBSlice(f func(i E, j E) bool) AnyBSlice[E] { 625 x.rwl.RLock() 626 defer x.rwl.RUnlock() 627 return x.es.SortFuncToBSlice(f) 628 } 629 630 func (x *SafeAnyBSlice[E]) SortComparator(f bcomparator.Comparator[E]) { 631 x.rwl.Lock() 632 defer x.rwl.Unlock() 633 x.es.SortComparator(f) 634 } 635 636 func (x *SafeAnyBSlice[E]) SortComparatorToSlice(f bcomparator.Comparator[E]) []E { 637 x.rwl.RLock() 638 defer x.rwl.RUnlock() 639 return x.es.SortComparatorToSlice(f) 640 } 641 642 func (x *SafeAnyBSlice[E]) SortComparatorToBSlice(f bcomparator.Comparator[E]) AnyBSlice[E] { 643 x.rwl.RLock() 644 defer x.rwl.RUnlock() 645 return x.es.SortComparatorToBSlice(f) 646 } 647 648 func (x *SafeAnyBSlice[E]) SortStableFunc(f func(i E, j E) bool) { 649 x.rwl.Lock() 650 defer x.rwl.Unlock() 651 x.es.SortStableFunc(f) 652 } 653 654 func (x *SafeAnyBSlice[E]) SortStableFuncToSlice(f func(i E, j E) bool) []E { 655 x.rwl.RLock() 656 defer x.rwl.RUnlock() 657 return x.es.SortStableFuncToSlice(f) 658 } 659 660 func (x *SafeAnyBSlice[E]) SortStableFuncToBSlice(f func(i E, j E) bool) AnyBSlice[E] { 661 x.rwl.RLock() 662 defer x.rwl.RUnlock() 663 return x.es.SortStableFuncToBSlice(f) 664 } 665 666 func (x *SafeAnyBSlice[E]) IsSortedFunc(f func(i E, j E) bool) bool { 667 x.rwl.RLock() 668 defer x.rwl.RUnlock() 669 return x.es.IsSortedFunc(f) 670 } 671 672 func (x *SafeAnyBSlice[E]) BinarySearchFunc(e E, f func(E, E) int) (int, bool) { 673 x.rwl.RLock() 674 defer x.rwl.RUnlock() 675 return x.es.BinarySearchFunc(e, f) 676 } 677 678 func (x *SafeAnyBSlice[E]) Filter(f func(E) bool) { 679 x.rwl.RLock() 680 defer x.rwl.RUnlock() 681 x.es.Filter(f) 682 } 683 684 func (x *SafeAnyBSlice[E]) FilterToSlice(f func(E) bool) []E { 685 x.rwl.RLock() 686 defer x.rwl.RUnlock() 687 return x.es.FilterToSlice(f) 688 } 689 690 func (x *SafeAnyBSlice[E]) FilterToBSlice(f func(E) bool) AnyBSlice[E] { 691 x.rwl.RLock() 692 defer x.rwl.RUnlock() 693 return x.es.FilterToBSlice(f) 694 } 695 696 func (x *SafeAnyBSlice[E]) Reverse() { 697 x.rwl.Lock() 698 defer x.rwl.Unlock() 699 x.es.Reverse() 700 } 701 702 func (x *SafeAnyBSlice[E]) ReverseToSlice() []E { 703 x.rwl.RLock() 704 defer x.rwl.RUnlock() 705 return x.es.ReverseToSlice() 706 } 707 708 func (x *SafeAnyBSlice[E]) ReverseToBSlice() AnyBSlice[E] { 709 x.rwl.RLock() 710 defer x.rwl.RUnlock() 711 return x.es.ReverseToBSlice() 712 } 713 714 func (x *SafeAnyBSlice[E]) ToMetaSlice() []E { 715 x.rwl.Lock() 716 defer x.rwl.Unlock() 717 return x.es.ToMetaSlice() 718 } 719 720 func (x *SafeAnyBSlice[E]) Append(e ...E) { 721 x.rwl.Lock() 722 defer x.rwl.Unlock() 723 x.es.Append(e...) 724 } 725 726 func (x *SafeAnyBSlice[E]) AppendToSlice(e ...E) []E { 727 x.rwl.RLock() 728 defer x.rwl.RUnlock() 729 return x.es.AppendToSlice(e...) 730 } 731 732 func (x *SafeAnyBSlice[E]) AppendToBSlice(e ...E) AnyBSlice[E] { 733 x.rwl.RLock() 734 defer x.rwl.RUnlock() 735 return x.es.AppendToBSlice(e...) 736 } 737 738 func (x *SafeAnyBSlice[E]) CopyToSlice() []E { 739 x.rwl.Lock() 740 defer x.rwl.Unlock() 741 return x.es.CopyToSlice() 742 } 743 744 func (x *SafeAnyBSlice[E]) CopyToBSlice() AnyBSlice[E] { 745 x.rwl.RLock() 746 defer x.rwl.RUnlock() 747 return x.es.CopyToBSlice() 748 } 749 750 func (x *SafeAnyBSlice[E]) GetByIndex(index int) E { 751 x.rwl.RLock() 752 defer x.rwl.RUnlock() 753 return x.es.GetByIndex(index) 754 } 755 756 func (x *SafeAnyBSlice[E]) GetByIndexE(index int) (E, error) { 757 x.rwl.RLock() 758 defer x.rwl.RUnlock() 759 return x.es.GetByIndexE(index) 760 } 761 762 func (x *SafeAnyBSlice[E]) GetByIndexOrDefault(index int, defaultE E) E { 763 x.rwl.RLock() 764 defer x.rwl.RUnlock() 765 return x.es.GetByIndexOrDefault(index, defaultE) 766 } 767 768 func (x *SafeAnyBSlice[E]) GetByRange(start int, end int) []E { 769 x.rwl.RLock() 770 defer x.rwl.RUnlock() 771 return x.es.GetByRange(start, end) 772 } 773 774 func (x *SafeAnyBSlice[E]) GetByRangeE(start int, end int) ([]E, error) { 775 x.rwl.RLock() 776 defer x.rwl.RUnlock() 777 return x.es.GetByRangeE(start, end) 778 } 779 780 func (x *SafeAnyBSlice[E]) SetByIndex(index int, e E) { 781 x.rwl.Lock() 782 defer x.rwl.Unlock() 783 x.es.SetByIndex(index, e) 784 785 } 786 787 func (x *SafeAnyBSlice[E]) SetByIndexE(index int, e E) error { 788 x.rwl.Lock() 789 defer x.rwl.Unlock() 790 return x.es.SetByIndexE(index, e) 791 } 792 793 func (x *SafeAnyBSlice[E]) SetByRange(index int, es []E) { 794 x.rwl.Lock() 795 defer x.rwl.Unlock() 796 x.es.SetByRange(index, es) 797 } 798 799 func (x *SafeAnyBSlice[E]) SetByRangeE(index int, es []E) error { 800 x.rwl.Lock() 801 defer x.rwl.Unlock() 802 return x.es.SetByRangeE(index, es) 803 }