Skip to content
This repository
tree: d5cf62d3f2
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 160 lines (121 sloc) 5.856 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
/*
// CWDoublyLinkedList.h
// Zangetsu
//
// Created by Colin Wheeler on 5/11/12.
// Copyright (c) 2012. All rights reserved.
//
Copyright (c) 2012 Colin Wheeler
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#import <Foundation/Foundation.h>

enum : NSUInteger {
kCWDoublyLinkedListEnumerateForward = 0,
kCWDoublyLinkedListEnumerateReverse = 1
};

@interface CWDoublyLinkedList : NSObject

/**
Returns a count of how many objects are present in the receiver
@return a NSUInteger with the receivers item count
*/
@property(readonly,assign) NSUInteger count;

/**
Appends anObject to the end of the receiver
This simply appends an object to the tail end of the receiver.
If anObject is nil then this method simply does nothing.
@praram an Object any valid Cocoa object
*/
-(void)addObject:(id)anObject;

/**
Inserts an object at the specified index
This method checks to make sure it has a valid Cocoa object, if it
doesn't it simply returns right away. Then it checks the index to
see if its valid. It must be within the bounds of the receiver or
at the very end. For example if you had a list with 3 objects in
it (0,1,2) and you said insert at index 3 this would be valid, in
that case it would simply perform -addObject: and return. Otherwise
this method inserts the object at the specified index.
@param anObject any valid Cocoa object
@param index a NSUInteger with a valid index
*/
-(void)insertObject:(id)anObject atIndex:(NSUInteger)index;

/**
Removes the object at a specified index in the receiver
First a check is done to see if the index is valid. If the index is
invalid then it checks to see if the list is empty. If either of these
true then the method immediately exits. Otherwise it goes to the
specified index and removes the node from the receiver.
@param NSUInteger a valid index within the bounds of the receiver
*/
-(void)removeObjectAtIndex:(NSUInteger)index;

/**
Removes the specified object from the receiver if found
This method simple enumerates through the contents of the receiver and
if it finds the object then it will remove it. Otherwise this will
enumerate through all objects in the receiver without finding anything
and then exit.
@param object any valid Cocoa object
*/
-(void)removeObject:(id)object;

/**
Returns the object at a specified index in the receiver
This method checks for the index being within the bounds of the receiver
and if not then it immediately exits. Otherwise it enumerates to the
specified index and returns the object associated with that index.
@param index a NSUInteger where you want the data associated with that slot in the receiver
*/
-(id)objectAtIndex:(NSUInteger)index;

-(id)objectAtIndexedSubscript:(NSUInteger)index;

-(void)setObject:(id)object atIndexedSubscript:(NSUInteger)idx;

/**
Swaps the objects at the given indexes with each other if both indexes are valid
@param index1 a NSUInteger index
@param index2 a NSUinteger index
*/
-(void)swapObjectAtIndex:(NSUInteger)index1 withIndex:(NSUInteger)index2;

/**
Returns a new CWDoublyLinkedList with the range given in the receiver
This method checks for a valid range. If the range is invalid then this
method immediately exits. Otherwise it adds the node in the receiver to
a new list and returns that list.
@param a NSRange for the receiver
@return if the range index is valid a new CWDoublyLinkedList instance, nil otherwise
*/
-(CWDoublyLinkedList *)linkedListWithRange:(NSRange)range;

/**
Enumerates the contents of the receiver
If the list is empty this method immediately exits. Otherwise this method
then starts at the front of the list and enumerates through all nodes
until it reaches the end.
@param object (block) the object being enumerated over
@param index (block) the index of the object being enumerated over
@param stop (block) a BOOL pointer which you can set to YES to stop enumeration
*/
-(void)enumerateObjectsWithBlock:(void(^)(id object,NSUInteger index, BOOL *stop))block;

/**
Enumerates the nodes of the receiver linked list
If the list is empty this method immediately exits. If kCWDoublyLinkedListEnumerateForward
is passed in then this is the same as calling -enumerateObjectsWithBlock: otherwise
passing in kCWDoublyLinkedListEnumerateReverse enumerates the nodes of the reseiver
starting at the end and goes backwards towards the front of the list.
@param option a NSUInteger corresponding to the way the list should be enumerated in
@param object (block) the object being enumerated over
@param index (block) the index of the object being enumerated over
@param stop (block) a BOOL pointer which you can set to YES to stop enumeration
*/
-(void)enumerateObjectsWithOption:(NSUInteger)option usingBlock:(void (^)(id object, NSUInteger index, BOOL *stop))block;

@end
Something went wrong with that request. Please try again.