Top Description Inners Fields Constructors Methods
org.python.modules._collections

public Class PyDeque

extends PyObject
implements Traverseproc
Class Inheritance
All Implemented Interfaces
org.python.core.Traverseproc
Known Direct Subclasses
org.python.modules._collections.PyDequeDerived
Annotations
@ExposedType
name:collections.deque
Imports
org.python.core.ArgParser, .PyIterator, .PyList, .PyObject, .PyTuple, .PyType, .Py, .PyException, .ThreadState, .Traverseproc, .Visitproc, org.python.expose.ExposedGet, .ExposedMethod, .ExposedNew, .ExposedSet, .ExposedType, .MethodType

PyDeque - This class implements the functionalities of Deque data structure. Deques are a generalization of stacks and queues (the name is pronounced 'deck' and is short for 'double-ended queue'). Deques support thread-safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction. Though list objects support similar operations, they are optimized for fast fixed-length operations and incur O(n) memory movement costs for pop(0) and insert(0, v) operations which change both the size and position of the underlying data representation. collections.deque([iterable[, maxlen]]) - returns a new deque object initialized left-to-right (using append()) with data from iterable. If iterable is not specified, the new deque is empty. If maxlen is not specified or is None, deques may grow to an arbitrary length. Otherwise, the deque is bounded to the specified maximum length. Once a bounded length deque is full, when new items are added, a corresponding number of items are discarded from the opposite end.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private class

Field Summary

Modifier and TypeField and Description
private PyDeque.Node
private int
private int
private long
public static final PyType
Inherited from org.python.core.PyObject:
attributesgcMonitorGlobalobjtype

Constructor Summary

AccessConstructor and Description
public
public
PyDeque(PyType subType)

Method Summary

Modifier and TypeMethod and Description
public void
__delitem__(PyObject
the key to be removed from the container
key
)

Overrides org.python.core.PyObject.__delitem__.

Equivalent to the standard Python __delitem__ method.

public synchronized PyObject
__eq__(PyObject
the object to compare this with.
o
)

Overrides org.python.core.PyObject.__eq__.

Equivalent to the standard Python __eq__ method.

public PyObject
__finditem__(PyObject
the key to lookup in this container
key
)

Overrides org.python.core.PyObject.__finditem__.

Very similar to the standard Python __getitem__ method.

public synchronized PyObject
__ge__(PyObject
the object to compare this with.
o
)

Overrides org.python.core.PyObject.__ge__.

Equivalent to the standard Python __ge__ method.

public synchronized PyObject
__gt__(PyObject
the object to compare this with.
o
)

Overrides org.python.core.PyObject.__gt__.

Equivalent to the standard Python __gt__ method.

public synchronized PyObject
__iadd__(PyObject
the object to perform this binary operation with (the right-hand operand).
o
)

Overrides org.python.core.PyObject.__iadd__.

Equivalent to the standard Python __iadd__ method.

public PyObject
__iter__()

Overrides org.python.core.PyObject.__iter__.

Return an iterator that is used to iterate the element of this sequence.

public synchronized PyObject
__le__(PyObject
the object to compare this with.
o
)

Overrides org.python.core.PyObject.__le__.

Equivalent to the standard Python __le__ method.

public int
__len__()

Overrides org.python.core.PyObject.__len__.

Equivalent to the standard Python __len__ method.

public synchronized PyObject
__lt__(PyObject
the object to compare this with.
o
)

Overrides org.python.core.PyObject.__lt__.

Equivalent to the standard Python __lt__ method.

public synchronized PyObject
__ne__(PyObject
the object to compare this with.
o
)

Overrides org.python.core.PyObject.__ne__.

Equivalent to the standard Python __ne__ method.

public boolean
__nonzero__()

Overrides org.python.core.PyObject.__nonzero__.

Equivalent to the standard Python __nonzero__ method.

public PyObject
__reduce__()

Overrides org.python.core.PyObject.__reduce__.

Used for pickling.

public void
__setitem__(PyObject
the key whose value will be set
index
,
PyObject
the value to set this key to
value
)

Overrides org.python.core.PyObject.__setitem__.

Equivalent to the standard Python __setitem__ method.

private PyDeque.Node
protected static int
cmp(PyObject o1, int ol1, PyObject o2, int ol2)

pack-priv final PyObject
pack-priv final synchronized void
pack-priv final synchronized PyObject
pack-priv final synchronized PyObject
pack-priv final synchronized PyObject
pack-priv final synchronized PyObject
pack-priv final synchronized PyObject
public final synchronized void
deque___init__(PyObject[] args, String[] kwds)

pack-priv final PyObject
pack-priv final synchronized PyObject
pack-priv final synchronized int
pack-priv final synchronized PyObject
pack-priv final synchronized PyObject
pack-priv final synchronized boolean
pack-priv final PyObject
pack-priv final synchronized void
public final synchronized void
deque_append(PyObject obj)

Add obj to the right side of the deque.

public final synchronized void
deque_appendleft(PyObject obj)

Add obj to the left side of the deque.

public final synchronized void
deque_clear()

Remove all elements from the deque leaving it with length 0.

public final synchronized PyObject
deque_count(PyObject x)

Count the number of deque elements equal to x.

public final synchronized void
deque_extend(PyObject iterable)

Extend the right side of the deque by appending elements from the iterable argument.

public final synchronized void
deque_extendleft(PyObject iterable)

Extend the left side of the deque by appending elements from iterable.

pack-priv final int
public final synchronized PyObject
deque_pop()

Remove and return an element from the right side of the deque.

public final synchronized PyObject
deque_popleft()

Remove and return an element from the left side of the deque.

public final synchronized PyObject
deque_remove(PyObject value)

Removed the first occurrence of value.

public final synchronized PyObject

Returns:

Py.None
deque_reverse
()

Reverse the elements of the deque in-place and then return None.

public final synchronized void
deque_rotate(int steps)

Rotate the deque n steps to the right.

pack-priv final synchronized String
public PyObject
getMaxlen()

If maxlen is not specified or is None, deques may grow to an arbitrary length.

private PyDeque.Node
public int
hashCode()

Overrides org.python.core.PyObject.hashCode.

Returns a hash code value for this object.

public boolean
public boolean
public boolean
private PyObject
public void
public String
toString()

Overrides org.python.core.PyObject.toString.

Returns a string representation of the object.

public synchronized int
traverse(Visitproc visit, Object arg)

Implements org.python.core.Traverseproc.traverse.

Traverses all directly contained PyObjects.

Inherited from org.python.core.PyObject:
__abs____add____and____call____call____call____call____call____call____call____call____call____call____call____call____call____call____call____call____cmp____coerce____coerce_ex____complex____contains____delattr____delattr____delete____delitem____delslice____delslice____dir____div____divmod____ensure_finalizer____findattr____findattr____findattr_ex____finditem____finditem____float____floordiv____format____get____getattr____getattr____getitem____getitem____getnewargs____getslice____getslice____hash____hex____iand____idiv____idivmod____ifloordiv____ilshift____imod____imul____index____int____invert____ior____ipow____irshift____isub____iternext____itruediv____ixor____long____lshift____mod____mul____neg____not____oct____or____pos____pow____pow____radd____rand____rawdir____rdiv____rdivmod____reduce_ex____reduce_ex____repr____rfloordiv____rlshift____rmod____rmul____ror____rpow____rrshift____rshift____rsub____rtruediv____rxor____set____setattr____setattr____setitem____setitem____setslice____setslice____str____sub____tojava____truediv____trunc____unicode____xor___add_and_callextra_cmp_div_divmod_doget_doget_doset_eq_floordiv_ge_gt_iadd_iand_idiv_idivmod_ifloordiv_ilshift_imod_imul_in_ior_ipow_irshift_is_isnot_isub_itruediv_ixor_jcall_jcallexc_jthrow_le_lshift_lt_mod_mul_ne_notin_or_pow_rshift_sub_truediv_unsupportedop_xoradaptToCoerceTupleasDoubleasIndexasIndexasIntasIntasIterableasLongasLongasNameasNameasStringasStringasStringOrNullasStringOrNullbit_lengthconjugatedelDictdelTypedispatch__init__equalsfastGetClassfastGetDictfinalizegetDictgetJavaProxygetTypeimpAttrimplementsDescrDeleteimplementsDescrGetimplementsDescrSetinvokeinvokeinvokeinvokeinvokeinvokeisCallableisDataDescrisIndexisIntegerisNumberTypemergeClassDictmergeDictAttrmergeListAttrnoAttributeErrorobject___subclasshook__readonlyAttributeErrorrunsupportedopMessagesetDictsetTypeunsupportedopMessage

Field Detail

maxlenback to summary
private int maxlen
sizeback to summary
private int size
stateback to summary
private long state
TYPEback to summary
public static final PyType TYPE

Hides org.python.core.PyObject.TYPE.

Constructor Detail

PyDequeback to summary
public PyDeque()
PyDequeback to summary
public PyDeque(PyType subType)

Method Detail

__delitem__back to summary
public void __delitem__(PyObject key)

Overrides org.python.core.PyObject.__delitem__.

Doc from org.python.core.PyObject.__delitem__.

Equivalent to the standard Python __delitem__ method.

Parameters
key:PyObject

the key to be removed from the container

Annotations
@Override
__eq__back to summary
public synchronized PyObject __eq__(PyObject o)

Overrides org.python.core.PyObject.__eq__.

Doc from org.python.core.PyObject.__eq__.

Equivalent to the standard Python __eq__ method.

Parameters
o:PyObject

the object to compare this with.

Returns:PyObject

the result of the comparison.

Annotations
@Override

__finditem__back to summary
public PyObject __finditem__(PyObject key)

Overrides org.python.core.PyObject.__finditem__.

Doc from org.python.core.PyObject.__finditem__.

Very similar to the standard Python __getitem__ method. Instead of throwing a KeyError if the item isn't found, this just returns null. Classes that wish to implement __getitem__ should override this method instead (with the appropriate semantics.

Parameters
key:PyObject

the key to lookup in this container

Returns:PyObject

the value corresponding to key or null if key is not found

Annotations
@Override

__ge__back to summary
public synchronized PyObject __ge__(PyObject o)

Overrides org.python.core.PyObject.__ge__.

Doc from org.python.core.PyObject.__ge__.

Equivalent to the standard Python __ge__ method.

Parameters
o:PyObject

the object to compare this with.

Returns:PyObject

the result of the comparison.

Annotations
@Override

__gt__back to summary
public synchronized PyObject __gt__(PyObject o)

Overrides org.python.core.PyObject.__gt__.

Doc from org.python.core.PyObject.__gt__.

Equivalent to the standard Python __gt__ method.

Parameters
o:PyObject

the object to compare this with.

Returns:PyObject

the result of the comparison.

Annotations
@Override

__iadd__back to summary
public synchronized PyObject __iadd__(PyObject o)

Overrides org.python.core.PyObject.__iadd__.

Doc from org.python.core.PyObject.__iadd__.

Equivalent to the standard Python __iadd__ method.

Parameters
o:PyObject

the object to perform this binary operation with (the right-hand operand).

Returns:PyObject

the result of the iadd, or null if this operation is not defined

Annotations
@Override

__iter__back to summary
public PyObject __iter__()

Overrides org.python.core.PyObject.__iter__.

Doc from org.python.core.PyObject.__iter__.

Return an iterator that is used to iterate the element of this sequence. From version 2.2, this method is the primary protocol for looping over sequences.

If a PyObject subclass should support iteration based in the __finditem__() method, it must supply an implementation of __iter__() like this:

public PyObject __iter__() {
    return new PySequenceIter(this);
}
When iterating over a python sequence from java code, it should be done with code like this:
for (PyObject item : seq.asIterable()) {
    // Do something with item
}
Annotations
@Override
__le__back to summary
public synchronized PyObject __le__(PyObject o)

Overrides org.python.core.PyObject.__le__.

Doc from org.python.core.PyObject.__le__.

Equivalent to the standard Python __le__ method.

Parameters
o:PyObject

the object to compare this with.

Returns:PyObject

the result of the comparison.

Annotations
@Override

__len__back to summary
public int __len__()

Overrides org.python.core.PyObject.__len__.

Doc from org.python.core.PyObject.__len__.

Equivalent to the standard Python __len__ method. Part of the mapping discipline.

Returns:int

the length of the object

Annotations
@Override

__lt__back to summary
public synchronized PyObject __lt__(PyObject o)

Overrides org.python.core.PyObject.__lt__.

Doc from org.python.core.PyObject.__lt__.

Equivalent to the standard Python __lt__ method.

Parameters
o:PyObject

the object to compare this with.

Returns:PyObject

the result of the comparison.

Annotations
@Override

__ne__back to summary
public synchronized PyObject __ne__(PyObject o)

Overrides org.python.core.PyObject.__ne__.

Doc from org.python.core.PyObject.__ne__.

Equivalent to the standard Python __ne__ method.

Parameters
o:PyObject

the object to compare this with.

Returns:PyObject

the result of the comparison.

Annotations
@Override

__nonzero__back to summary
public boolean __nonzero__()

Overrides org.python.core.PyObject.__nonzero__.

Doc from org.python.core.PyObject.__nonzero__.

Equivalent to the standard Python __nonzero__ method. Returns whether of not a given PyObject is considered true.

Annotations
@Override
__reduce__back to summary
public PyObject __reduce__()

Overrides org.python.core.PyObject.__reduce__.

Doc from org.python.core.PyObject.__reduce__.

Used for pickling. Default implementation calls object___reduce__.

Returns:PyObject

a tuple of (class, tuple)

Annotations
@Override

__setitem__back to summary
public void __setitem__(PyObject index, PyObject value)

Overrides org.python.core.PyObject.__setitem__.

Doc from org.python.core.PyObject.__setitem__.

Equivalent to the standard Python __setitem__ method.

Parameters
index:PyObject

the key whose value will be set

value:PyObject

the value to set this key to

Annotations
@Override
addBeforeback to summary
private PyDeque.Node addBefore(PyObject obj, PyDeque.Node node)
cmpback to summary
protected static int cmp(PyObject o1, int ol1, PyObject o2, int ol2)
deque___copy__back to summary
pack-priv final PyObject deque___copy__()
Annotations
@ExposedMethod
deque___delitem__back to summary
pack-priv final synchronized void deque___delitem__(PyObject key)
Annotations
@ExposedMethod
deque___eq__back to summary
pack-priv final synchronized PyObject deque___eq__(PyObject o)
Annotations
@ExposedMethod
type:BINARY
deque___ge__back to summary
pack-priv final synchronized PyObject deque___ge__(PyObject o)
Annotations
@ExposedMethod
type:BINARY
deque___getitem__back to summary
pack-priv final synchronized PyObject deque___getitem__(PyObject index)
Annotations
@ExposedMethod
deque___gt__back to summary
pack-priv final synchronized PyObject deque___gt__(PyObject o)
Annotations
@ExposedMethod
type:BINARY
deque___iadd__back to summary
pack-priv final synchronized PyObject deque___iadd__(PyObject o)
Annotations
@ExposedMethod
type:BINARY
deque___init__back to summary
public final synchronized void deque___init__(PyObject[] args, String[] kwds)
Annotations
@ExposedNew
@ExposedMethod
deque___iter__back to summary
pack-priv final PyObject deque___iter__()
Annotations
@ExposedMethod
deque___le__back to summary
pack-priv final synchronized PyObject deque___le__(PyObject o)
Annotations
@ExposedMethod
type:BINARY
deque___len__back to summary
pack-priv final synchronized int deque___len__()
Annotations
@ExposedMethod
deque___lt__back to summary
pack-priv final synchronized PyObject deque___lt__(PyObject o)
Annotations
@ExposedMethod
type:BINARY
deque___ne__back to summary
pack-priv final synchronized PyObject deque___ne__(PyObject o)
Annotations
@ExposedMethod
type:BINARY
deque___nonzero__back to summary
pack-priv final synchronized boolean deque___nonzero__()
Annotations
@ExposedMethod
deque___reduce__back to summary
pack-priv final PyObject deque___reduce__()
Annotations
@ExposedMethod
deque___setitem__back to summary
pack-priv final synchronized void deque___setitem__(PyObject index, PyObject value)
Annotations
@ExposedMethod
deque_appendback to summary
public final synchronized void deque_append(PyObject obj)

Add obj to the right side of the deque.

Annotations
@ExposedMethod
deque_appendleftback to summary
public final synchronized void deque_appendleft(PyObject obj)

Add obj to the left side of the deque.

Annotations
@ExposedMethod
deque_clearback to summary
public final synchronized void deque_clear()

Remove all elements from the deque leaving it with length 0.

Annotations
@ExposedMethod
deque_countback to summary
public final synchronized PyObject deque_count(PyObject x)

Count the number of deque elements equal to x.

Annotations
@ExposedMethod
deque_extendback to summary
public final synchronized void deque_extend(PyObject iterable)

Extend the right side of the deque by appending elements from the iterable argument.

Annotations
@ExposedMethod
deque_extendleftback to summary
public final synchronized void deque_extendleft(PyObject iterable)

Extend the left side of the deque by appending elements from iterable. Note, the series of left appends results in reversing the order of elements in the iterable argument.

Annotations
@ExposedMethod
deque_hashCodeback to summary
pack-priv final int deque_hashCode()
Annotations
@ExposedMethod
names:__hash__
deque_popback to summary
public final synchronized PyObject deque_pop()

Remove and return an element from the right side of the deque. If no elements are present, raises an IndexError.

Annotations
@ExposedMethod
deque_popleftback to summary
public final synchronized PyObject deque_popleft()

Remove and return an element from the left side of the deque. If no elements are present, raises an IndexError.

Annotations
@ExposedMethod
deque_removeback to summary
public final synchronized PyObject deque_remove(PyObject value)

Removed the first occurrence of value. If not found, raises a ValueError.

Annotations
@ExposedMethod
deque_reverseback to summary
public final synchronized PyObject deque_reverse()

Reverse the elements of the deque in-place and then return None.

Returns:PyObject

Py.None

Annotations
@ExposedMethod

deque_rotateback to summary
public final synchronized void deque_rotate(int steps)

Rotate the deque n steps to the right. If n is negative, rotate to the left. Rotating one step to the right is equivalent to: d.appendleft(d.pop()).

Annotations
@ExposedMethod
defaults:1
deque_toStringback to summary
pack-priv final synchronized String deque_toString()
Annotations
@ExposedMethod
names:__repr__
getMaxlenback to summary
public PyObject getMaxlen()

If maxlen is not specified or is None, deques may grow to an arbitrary length. Otherwise, the deque is bounded to the specified maximum length.

Annotations
@ExposedGet
name:maxlen
getNodeback to summary
private PyDeque.Node getNode(PyObject index)
hashCodeback to summary
public int hashCode()

Overrides org.python.core.PyObject.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override

isMappingTypeback to summary
public boolean isMappingType()

Overrides org.python.core.PyObject.isMappingType.

Annotations
@Override
isSequenceTypeback to summary
public boolean isSequenceType()

Overrides org.python.core.PyObject.isSequenceType.

Annotations
@Override
refersDirectlyToback to summary
public boolean refersDirectlyTo(PyObject ob) throws UnsupportedOperationException

Implements org.python.core.Traverseproc.refersDirectlyTo.

Doc from org.python.core.Traverseproc.refersDirectlyTo.

Optional operation. Should only be implemented if it is more efficient than calling traverse(Visitproc, Object) with a visitproc that just watches out for ob. Must return false if ob is null.

Annotations
@Override
removeNodeback to summary
private PyObject removeNode(PyDeque.Node node)
setMaxlenback to summary
public void setMaxlen(PyObject o)
Annotations
@ExposedSet
name:maxlen
toStringback to summary
public String toString()

Overrides org.python.core.PyObject.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override

traverseback to summary
public synchronized int traverse(Visitproc visit, Object arg)

Implements org.python.core.Traverseproc.traverse.

Doc from org.python.core.Traverseproc.traverse.

Traverses all directly contained PyObjects. Like in CPython, arg must be passed unmodified to visit as its second parameter. If Visitproc#visit(PyObject, Object) returns nonzero, this return value must be returned immediately by traverse. Visitproc#visit(PyObject, Object) must not be called with a null PyObject-argument.

Annotations
@Override
org.python.modules._collections back to summary

private Class PyDeque.Node

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private PyObject
private PyDeque.Node
private PyDeque.Node

Constructor Summary

AccessConstructor and Description
pack-priv
Node(PyObject data, PyDeque.Node right, PyDeque.Node left)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

databack to summary
private PyObject data
leftback to summary
private PyDeque.Node left
rightback to summary
private PyDeque.Node right

Constructor Detail

Nodeback to summary
pack-priv Node(PyObject data, PyDeque.Node right, PyDeque.Node left)
org.python.modules._collections back to summary

private Class PyDeque.PyDequeIter

extends PyIterator
Class Inheritance

Field Summary

Modifier and TypeField and Description
private PyDeque.Node
private long
Inherited from org.python.core.PyIterator:
__doc__nextstopException

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public PyObject
__iternext__()

Implements abstract org.python.core.PyIterator.__iternext__.

Return the next element of the sequence that this is an iterator for.

public boolean
public int
traverse(Visitproc visit, Object arg)

Overrides org.python.core.PyIterator.traverse.

Implements org.python.core.Traverseproc.traverse.

Traverses all directly contained PyObjects.

Inherited from org.python.core.PyIterator:
__iter____tojava__doNextiteratornext

Field Detail

lastReturnedback to summary
private PyDeque.Node lastReturned
startStateback to summary
private long startState

Constructor Detail

PyDequeIterback to summary
public PyDequeIter()

Method Detail

__iternext__back to summary
public PyObject __iternext__()

Implements abstract org.python.core.PyIterator.__iternext__.

Doc from org.python.core.PyObject.__iternext__.

Return the next element of the sequence that this is an iterator for. Returns null when the end of the sequence is reached.

Annotations
@Override
refersDirectlyToback to summary
public boolean refersDirectlyTo(PyObject ob) throws UnsupportedOperationException

Overrides org.python.core.PyIterator.refersDirectlyTo.

Implements org.python.core.Traverseproc.refersDirectlyTo.

Doc from org.python.core.Traverseproc.refersDirectlyTo.

Optional operation. Should only be implemented if it is more efficient than calling traverse(Visitproc, Object) with a visitproc that just watches out for ob. Must return false if ob is null.

Annotations
@Override
traverseback to summary
public int traverse(Visitproc visit, Object arg)

Overrides org.python.core.PyIterator.traverse.

Implements org.python.core.Traverseproc.traverse.

Doc from org.python.core.Traverseproc.traverse.

Traverses all directly contained PyObjects. Like in CPython, arg must be passed unmodified to visit as its second parameter. If Visitproc#visit(PyObject, Object) returns nonzero, this return value must be returned immediately by traverse. Visitproc#visit(PyObject, Object) must not be called with a null PyObject-argument.

Annotations
@Override