[Python-checkins] python/dist/src/Modules collectionsmodule.c, 1.4, 1.5

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Sat Feb 7 16:13:02 EST 2004


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8513/Modules

Modified Files:
	collectionsmodule.c 
Log Message:
* Incorporate Skip's suggestions for documentation  (explain the word deque
  comes from and show the differences from lists).
* Add a rotate() method.



Index: collectionsmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/collectionsmodule.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** collectionsmodule.c	7 Feb 2004 02:45:22 -0000	1.4
--- collectionsmodule.c	7 Feb 2004 21:13:00 -0000	1.5
***************
*** 245,248 ****
--- 245,286 ----
  "Extend the left side of the deque with elements from the iterable");
  
+ static PyObject *
+ deque_rotate(dequeobject *deque, PyObject *args)
+ {
+ 	int i, n;
+ 	PyObject *item, *rv;
+ 
+ 	if (!PyArg_ParseTuple(args, "i:rotate", &n))
+ 		return NULL;
+ 
+ 	if (n == 0  ||  deque->len == 0)
+ 		Py_RETURN_NONE;
+ 
+ 	for (i=0 ; i<n ; i++) {
+ 		item = deque_pop(deque, NULL);
+ 		if (item == NULL)
+ 			return NULL;
+ 		rv = deque_appendleft(deque, item);
+ 		Py_DECREF(item);
+ 		if (rv == NULL)
+ 			return NULL;
+ 		Py_DECREF(rv);
+ 	}
+ 	for (i=0 ; i>n ; i--) {
+ 		item = deque_popleft(deque, NULL);
+ 		if (item == NULL)
+ 			return NULL;
+ 		rv = deque_append(deque, item);
+ 		Py_DECREF(item);
+ 		if (rv == NULL)
+ 			return NULL;
+ 		Py_DECREF(rv);
+ 	}
+ 	Py_RETURN_NONE;
+ }
+ 
+ PyDoc_STRVAR(rotate_doc, 
+ "Rotate the deque n steps to the right.  If n is negative, rotates left.");
+ 
  static int
  deque_len(dequeobject *deque)
***************
*** 462,465 ****
--- 500,507 ----
  	{"__copy__",		(PyCFunction)deque_copy,	
  		METH_NOARGS,	 copy_doc},
+ 	{"extend",		(PyCFunction)deque_extend,	
+ 		METH_O,		 extend_doc},
+ 	{"extendleft",	(PyCFunction)deque_extendleft,	
+ 		METH_O,		 extendleft_doc},
  	{"pop",			(PyCFunction)deque_pop,	
  		METH_NOARGS,	 pop_doc},
***************
*** 470,477 ****
  	{"__reversed__",	(PyCFunction)deque_reviter,	
  		METH_NOARGS,	 reversed_doc},
! 	{"extend",		(PyCFunction)deque_extend,	
! 		METH_O,		 extend_doc},
! 	{"extendleft",	(PyCFunction)deque_extendleft,	
! 		METH_O,		 extendleft_doc},
  	{NULL,		NULL}	/* sentinel */
  };
--- 512,517 ----
  	{"__reversed__",	(PyCFunction)deque_reviter,	
  		METH_NOARGS,	 reversed_doc},
! 	{"rotate",		(PyCFunction)deque_rotate,	
! 		METH_VARARGS,	rotate_doc},
  	{NULL,		NULL}	/* sentinel */
  };




More information about the Python-checkins mailing list