picofuse-objc

Instance Methods | Class Methods | List of all members

Objects found by keys, which can be changed. More...

#import <Foundation/Foundation.h>

Inheritance diagram for NXMap:
Inheritance graph
[legend]
Collaboration diagram for NXMap:
Collaboration graph
[legend]

Instance Methods

(id) - initWithCapacity:
 Initializes an empty map with room for a number of keys.
 
(size_t) - count
 Returns the number of keys.
 
(id) - objectForKey:
 Returns the object for a key, or nil if there isn't one.
 
(BOOL) - containsObject:
 Returns YES if there's an object for a key.
 
(BOOL) - setObject:forKey:
 Sets the object for a key, replacing any it had. More...
 
(BOOL) - removeObjectForKey:
 Removes a key and its object. More...
 
(void) - removeAllObjects
 Removes every key and object, but keeps the room for them.
 
(NXArray *) - allKeys
 Returns the keys, in no particular order, or nil if there isn't enough memory.
 
(NXArray *) - allObjects
 Returns the objects, in the same order as allKeys, or nil if there isn't enough memory.
 
(BOOL) - isEqual:
 Returns YES if another object is a map with equal keys, by isEqual:, which have equal objects.
 
(uintptr_t) - hash
 Returns a hash of the keys and objects, which is the same for equal maps.
 
(id) - copy
 Returns a new map of the same keys and objects, or nil if there isn't enough memory. More...
 
(NXString *) - description
 Returns the descriptions of the keys and objects, such as "{a: 1, b: 2}".
 
- Instance Methods inherited from NXObject
(void) - dealloc
 Frees the instance. More...
 
(NXZone *) - zone
 Returns the zone in which the instance was allocated. More...
 
(id) - retain
 Increases the retain count of the receiver. More...
 
(void) - release
 Decreases the retain count of the receiver. More...
 
(id) - autorelease
 Releases the receiver later, when the current autorelease pool of the thread is drained. More...
 
- Instance Methods inherited from Object
(id) - init
 Initialize the instance, after allocation. More...
 
(Class) - class
 Returns the class of the instance. More...
 
(Class) - superclass
 Returns the superclass of the instance. More...
 
(BOOL) - isKindOfClass:
 Returns a Boolean value that indicates whether the receiver is an instance of a given class. More...
 
(BOOL) - conformsTo:
 Checks if the receiver's class conforms to a protocol. More...
 
- Instance Methods inherited from <ObjectProtocol>
(BOOL) - respondsToSelector:
 Checks if the receiver responds to a selector. More...
 
- Instance Methods inherited from <NXFastEnumeration>
(unsigned long) - countByEnumeratingWithState:objects:count:
 Returns the next batch of objects for a for...in loop. More...
 

Class Methods

(id) + map
 Returns an empty map.
 
(id) + mapWithCapacity:
 Returns an empty map with room for a number of keys. More...
 
(id) + mapWithKeysAndObjects:
 Returns a map of keys and objects, in pairs of a key and then its object, which end with nil. More...
 
(id) + mapWithObjects:forKeys:
 Returns a map of keys and objects from two arrays: the first key is for the first object, the second for the second, and so on. More...
 
- Class Methods inherited from NXObject
(id) + alloc
 Allocates a new instance in the default zone, or if there isn't one, with sys_calloc(). More...
 
(id) + allocWithZone:
 Allocates a new instance in a specific zone. More...
 
(id) + new
 Allocates and initializes a new instance, as [[cls alloc] init] does. More...
 
- Class Methods inherited from Object
(void) + initialize
 Performs one-time initialization for the class. More...
 
(Class) + class
 Returns the class object. More...
 
(Class) + superclass
 Returns the superclass of the class. More...
 
(const char *) + name
 Returns the name of the class. More...
 
(BOOL) + conformsTo:
 Checks if the class conforms to a protocol. More...
 

Additional Inherited Members

- Protected Attributes inherited from Object
Class isa
 A pointer to the object's class structure. More...
 

Detailed Description

Objects found by keys, which can be changed.

Any object can be a key, as they're found by hash and isEqual:. A map keeps a copy of each key, so changing the key afterwards doesn't change the map: for a string which can't change, the copy is the same string. Objects are retained while they're in the map, and released when they're removed or replaced or the map is deallocated. Neither a key nor an object can be nil, so NXNull is used instead.

The keys and objects are kept in a table in memory from the map's zone, which is twice as big when it would be three-quarters full. The order of keys isn't defined.

A for...in loop goes through the keys. Adding or removing keys in the loop panics, unless it then stops with break, but setting the object for a key which is there doesn't.

Any number of threads can read a map at once, but while one changes it, no other thread can use it, and it doesn't lock itself. See Threads and mutable objects.

Definition at line 31 of file NXMap.h.

Method Documentation

◆ copy()

- (id) copy

Returns a new map of the same keys and objects, or nil if there isn't enough memory.

The caller owns it and has to release it.

Implements NXObject.

◆ mapWithCapacity:()

+ (id) mapWithCapacity: (size_t)  capacity

Returns an empty map with room for a number of keys.

Returns
The map, or nil if there isn't enough memory.

◆ mapWithKeysAndObjects:()

+ (id) mapWithKeysAndObjects: (id)  firstKey
,   ... 

Returns a map of keys and objects, in pairs of a key and then its object, which end with nil.

Returns
The map, or nil if there isn't enough memory.

◆ mapWithObjects:forKeys:()

+ (id) mapWithObjects: (NXArray *)  objects
forKeys: (NXArray *)  keys 

Returns a map of keys and objects from two arrays: the first key is for the first object, the second for the second, and so on.

Parameters
objectsThe objects.
keysThe keys, as many as there are objects. A key which is in the array more than once is for the last of its objects.
Returns
The map, or nil if the arrays have different counts, or there isn't enough memory.

◆ removeObjectForKey:()

- (BOOL) removeObjectForKey: (id)  key

Removes a key and its object.

Returns
YES if it was removed, or NO if there wasn't one.

◆ setObject:forKey:()

- (BOOL) setObject: (id)  object
forKey: (id)  key 

Sets the object for a key, replacing any it had.

Returns
YES if it was set, or NO if the key or object is nil, or there isn't enough memory.

The documentation for this class was generated from the following file: