Differences From Artifact [69937f5d0f]:
- File
src/OFMapTable.m
— part of check-in
[44f45c2e35]
at
2017-01-09 17:36:36
on branch trunk
— Update copyright
Forgot to add 2017, even though I already did quite some changes in
2017. (user: js, size: 16788) [annotate] [blame] [check-ins using]
To Artifact [0faf59214b]:
- File
src/OFMapTable.m
— part of check-in
[4af49a13c3]
at
2017-05-07 20:10:13
on branch trunk
— Small code style change
Casts are now written like types in variable declarations. (user: js, size: 16814) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
33 34 35 36 37 38 39 | struct of_map_table_bucket { void *key, *object; uint32_t hash; }; static struct of_map_table_bucket deleted = { 0 }; | | | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | struct of_map_table_bucket { void *key, *object; uint32_t hash; }; static struct of_map_table_bucket deleted = { 0 }; static void * defaultRetain(void *object) { return object; } static void defaultRelease(void *object) |
︙ | ︙ | |||
57 58 59 60 61 62 63 | static bool defaultEqual(void *object1, void *object2) { return (object1 == object2); } @interface OFMapTable () | | | | | | | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | static bool defaultEqual(void *object1, void *object2) { return (object1 == object2); } @interface OFMapTable () - (void)OF_setObject: (void *)object forKey: (void *)key hash: (uint32_t)hash; @end @interface OFMapTableEnumerator () - (instancetype)OF_initWithMapTable: (OFMapTable *)mapTable buckets: (struct of_map_table_bucket **)buckets capacity: (uint32_t)capacity mutationsPointer: (unsigned long *)mutationsPtr; @end @interface OFMapTableKeyEnumerator: OFMapTableEnumerator @end @interface OFMapTableObjectEnumerator: OFMapTableEnumerator @end |
︙ | ︙ | |||
257 258 259 260 261 262 263 | } - (size_t)count { return _count; } | | | 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | } - (size_t)count { return _count; } - (void *)objectForKey: (void *)key { uint32_t i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exception]; hash = OF_ROL(_keyFunctions.hash(key), _rotate); |
︙ | ︙ | |||
353 354 355 356 357 358 359 | } [self freeMemory: _buckets]; _buckets = buckets; _capacity = capacity; } | | | | 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | } [self freeMemory: _buckets]; _buckets = buckets; _capacity = capacity; } - (void)OF_setObject: (void *)object forKey: (void *)key hash: (uint32_t)hash { uint32_t i, last; void *old; if (key == NULL || object == NULL) @throw [OFInvalidArgumentException exception]; |
︙ | ︙ | |||
441 442 443 444 445 446 447 | } old = _buckets[i]->object; _buckets[i]->object = _objectFunctions.retain(object); _objectFunctions.release(old); } | | | | | 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | } old = _buckets[i]->object; _buckets[i]->object = _objectFunctions.retain(object); _objectFunctions.release(old); } - (void)setObject: (void *)object forKey: (void *)key { [self OF_setObject: object forKey: key hash: _keyFunctions.hash(key)]; } - (void)removeObjectForKey: (void *)key { uint32_t i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exception]; hash = OF_ROL(_keyFunctions.hash(key), _rotate); |
︙ | ︙ | |||
542 543 544 545 546 547 548 | #elif defined(HAVE_RANDOM) _rotate = random() & 31; #else _rotate = rand() & 31; #endif } | | | | | | | | 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 | #elif defined(HAVE_RANDOM) _rotate = random() & 31; #else _rotate = rand() & 31; #endif } - (bool)containsObject: (void *)object { if (object == NULL || _count == 0) return false; for (uint32_t i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deleted) if (_objectFunctions.equal(_buckets[i]->object, object)) return true; return false; } - (bool)containsObjectIdenticalTo: (void *)object { if (object == NULL || _count == 0) return false; for (uint32_t i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deleted) if (_buckets[i]->object == object) return true; return false; } - (OFMapTableEnumerator *)keyEnumerator { return [[[OFMapTableKeyEnumerator alloc] OF_initWithMapTable: self buckets: _buckets capacity: _capacity mutationsPointer: &_mutations] autorelease]; } - (OFMapTableEnumerator *)objectEnumerator { return [[[OFMapTableObjectEnumerator alloc] OF_initWithMapTable: self buckets: _buckets capacity: _capacity mutationsPointer: &_mutations] autorelease]; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state objects: (id *)objects count: (int)count { uint32_t j = (uint32_t)state->state; int i; for (i = 0; i < count; i++) { for (; j < _capacity && (_buckets[j] == NULL || |
︙ | ︙ | |||
661 662 663 664 665 666 667 | @implementation OFMapTableEnumerator - init { OF_INVALID_INIT_METHOD } | | | | | | | | | 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 | @implementation OFMapTableEnumerator - init { OF_INVALID_INIT_METHOD } - (instancetype)OF_initWithMapTable: (OFMapTable *)mapTable buckets: (struct of_map_table_bucket **)buckets capacity: (uint32_t)capacity mutationsPointer: (unsigned long *)mutationsPtr { self = [super init]; _mapTable = [mapTable retain]; _buckets = buckets; _capacity = capacity; _mutations = *mutationsPtr; _mutationsPtr = mutationsPtr; return self; } - (void)dealloc { [_mapTable release]; [super dealloc]; } - (void *)nextObject { OF_UNRECOGNIZED_SELECTOR } - (void)reset { if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithObject: _mapTable]; _position = 0; } @end @implementation OFMapTableKeyEnumerator - (void *)nextObject { if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithObject: _mapTable]; for (; _position < _capacity && (_buckets[_position] == NULL || _buckets[_position] == &deleted); _position++); if (_position < _capacity) return _buckets[_position++]->key; else return NULL; } @end @implementation OFMapTableObjectEnumerator - (void *)nextObject { if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithObject: _mapTable]; for (; _position < _capacity && (_buckets[_position] == NULL || _buckets[_position] == &deleted); _position++); if (_position < _capacity) return _buckets[_position++]->object; else return NULL; } @end @implementation OFMapTable_EnumeratorWrapper - initWithEnumerator: (OFMapTableEnumerator *)enumerator object: (id)object { self = [super init]; _enumerator = [enumerator retain]; _object = [object retain]; |
︙ | ︙ |