Changeset 3203 for trunk/Ohana/src/opihi/pcontrol/QueueOps.c
- Timestamp:
- Feb 12, 2005, 9:34:34 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/pcontrol/QueueOps.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/pcontrol/QueueOps.c
r3187 r3203 2 2 3 3 /* get object from point in stack (negative == distance from end) */ 4 void *Get Queue (Queue *queue, int where) {4 void *GetStack (Stack *stack, int where) { 5 5 6 6 int i; 7 7 void *object; 8 8 9 /* QUEUE_TOP == 0, QUEUE_BOTTOM == -1 */9 /* STACK_TOP == 0, STACK_BOTTOM == -1 */ 10 10 /* this code correctly handles the negative 'where' and Nobject == 0 */ 11 if (where < 0) where += queue[0].Nobject;11 if (where < 0) where += stack[0].Nobject; 12 12 if (where < 0) return (NULL); 13 if (where >= queue[0].Nobject) return (NULL);13 if (where >= stack[0].Nobject) return (NULL); 14 14 15 object = queue[0].object[where];16 queue[0].Nobject --;17 for (i = where; i < queue[0].Nobject; i++) {18 queue[0].object[i] = queue[0].object[i+1];15 object = stack[0].object[where]; 16 stack[0].Nobject --; 17 for (i = where; i < stack[0].Nobject; i++) { 18 stack[0].object[i] = stack[0].object[i+1]; 19 19 } 20 20 return (object); … … 22 22 23 23 /* push object on top of stack */ 24 int Put Queue (Queue *queue, int where, void *object) {24 int PutStack (Stack *stack, int where, void *object) { 25 25 26 26 int i; 27 27 28 /* QUEUE_TOP == 0, QUEUE_BOTTOM == -1 */28 /* STACK_TOP == 0, STACK_BOTTOM == -1 */ 29 29 /* this code correctly handles the negative 'where' and Nobject == 0 */ 30 if (where < 0) where += queue[0].Nobject + 1;30 if (where < 0) where += stack[0].Nobject + 1; 31 31 if (where < 0) return (FALSE); 32 if (where > queue[0].Nobject) return (FALSE);32 if (where > stack[0].Nobject) return (FALSE); 33 33 34 /* extend queueas needed */35 if ( queue[0].Nobject >= queue[0].NOBJECT) {36 queue[0].NOBJECT += 100;37 REALLOCATE ( queue[0].object, void *, queue[0].NOBJECT);34 /* extend stack as needed */ 35 if (stack[0].Nobject >= stack[0].NOBJECT) { 36 stack[0].NOBJECT += 100; 37 REALLOCATE (stack[0].object, void *, stack[0].NOBJECT); 38 38 } 39 39 40 for (i = queue[0].Nobject; i > where; i--) {41 queue[0].object[i] = queue[0].object[i-1];40 for (i = stack[0].Nobject; i > where; i--) { 41 stack[0].object[i] = stack[0].object[i-1]; 42 42 } 43 queue[0].object[where] = object;44 queue[0].Nobject ++;43 stack[0].object[where] = object; 44 stack[0].Nobject ++; 45 45 return (TRUE); 46 46 } 47 47 48 /* allocate queue, setup with default values, allocate data */49 Queue *InitQueue() {48 /* allocate stack, setup with default values, allocate data */ 49 Stack *InitStack () { 50 50 51 Queue *queue;51 Stack *stack; 52 52 53 ALLOCATE ( queue, Queue, 1);53 ALLOCATE (stack, Stack, 1); 54 54 55 queue[0].Nobject = 0;56 queue[0].NOBJECT = 50;57 ALLOCATE ( queue[0].object, void *, queue[0].NOBJECT);58 return ( queue);55 stack[0].Nobject = 0; 56 stack[0].NOBJECT = 50; 57 ALLOCATE (stack[0].object, void *, stack[0].NOBJECT); 58 return (stack); 59 59 } 60 60 61 /* these queues are not super efficient, and should probably be replaced with linked lists,61 /* these stacks are not super efficient, and should probably be replaced with linked lists, 62 62 but I find these easier to get my brain around 63 63 */
Note:
See TracChangeset
for help on using the changeset viewer.
