Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
ce8185e6
Commit
ce8185e6
authored
Aug 13, 2005
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More function re-ordering (placing like functions together).
parent
ed6c1ef8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
86 deletions
+86
-86
Objects/setobject.c
Objects/setobject.c
+86
-86
No files found.
Objects/setobject.c
View file @
ce8185e6
...
...
@@ -566,6 +566,57 @@ set_contains_entry(PySetObject *so, setentry *entry)
return
key
!=
NULL
&&
key
!=
dummy
;
}
static
PyObject
*
set_pop
(
PySetObject
*
so
)
{
PyObject
*
key
;
register
setentry
*
entry
;
register
int
i
=
0
;
assert
(
PyAnySet_Check
(
so
));
if
(
so
->
used
==
0
)
{
PyErr_SetString
(
PyExc_KeyError
,
"pop from an empty set"
);
return
NULL
;
}
/* Set entry to "the first" unused or dummy set entry. We abuse
* the hash field of slot 0 to hold a search finger:
* If slot 0 has a value, use slot 0.
* Else slot 0 is being used to hold a search finger,
* and we use its hash value as the first index to look.
*/
entry
=
&
so
->
table
[
0
];
if
(
entry
->
key
==
NULL
||
entry
->
key
==
dummy
)
{
i
=
(
int
)
entry
->
hash
;
/* The hash field may be a real hash value, or it may be a
* legit search finger, or it may be a once-legit search
* finger that's out of bounds now because it wrapped around
* or the table shrunk -- simply make sure it's in bounds now.
*/
if
(
i
>
so
->
mask
||
i
<
1
)
i
=
1
;
/* skip slot 0 */
while
((
entry
=
&
so
->
table
[
i
])
->
key
==
NULL
||
entry
->
key
==
dummy
)
{
i
++
;
if
(
i
>
so
->
mask
)
i
=
1
;
}
}
key
=
entry
->
key
;
Py_INCREF
(
dummy
);
entry
->
key
=
dummy
;
so
->
used
--
;
so
->
table
[
0
].
hash
=
i
+
1
;
/* next place to start */
return
key
;
}
PyDoc_STRVAR
(
pop_doc
,
"Remove and return an arbitrary set element."
);
static
int
set_len
(
PyObject
*
so
)
{
return
((
PySetObject
*
)
so
)
->
used
;
}
/***** Set iterator type ***********************************************/
static
PyTypeObject
PySetIter_Type
;
/* Forward */
...
...
@@ -682,12 +733,6 @@ static PyTypeObject PySetIter_Type = {
(
iternextfunc
)
setiter_iternext
,
/* tp_iternext */
};
static
int
set_len
(
PyObject
*
so
)
{
return
((
PySetObject
*
)
so
)
->
used
;
}
static
int
set_update_internal
(
PySetObject
*
so
,
PyObject
*
other
)
{
...
...
@@ -918,41 +963,6 @@ set_swap_bodies(PySetObject *a, PySetObject *b)
}
}
static
int
set_contains
(
PySetObject
*
so
,
PyObject
*
key
)
{
PyObject
*
tmpkey
;
int
rv
;
rv
=
set_contains_key
(
so
,
key
);
if
(
rv
==
-
1
)
{
if
(
!
PyAnySet_Check
(
key
)
||
!
PyErr_ExceptionMatches
(
PyExc_TypeError
))
return
-
1
;
PyErr_Clear
();
tmpkey
=
make_new_set
(
&
PyFrozenSet_Type
,
NULL
);
if
(
tmpkey
==
NULL
)
return
-
1
;
set_swap_bodies
((
PySetObject
*
)
tmpkey
,
(
PySetObject
*
)
key
);
rv
=
set_contains
(
so
,
tmpkey
);
set_swap_bodies
((
PySetObject
*
)
tmpkey
,
(
PySetObject
*
)
key
);
Py_DECREF
(
tmpkey
);
}
return
rv
;
}
static
PyObject
*
set_direct_contains
(
PySetObject
*
so
,
PyObject
*
key
)
{
long
result
;
result
=
set_contains
(
so
,
key
);
if
(
result
==
-
1
)
return
NULL
;
return
PyBool_FromLong
(
result
);
}
PyDoc_STRVAR
(
contains_doc
,
"x.__contains__(y) <==> y in x."
);
static
PyObject
*
set_copy
(
PySetObject
*
so
)
{
...
...
@@ -1537,6 +1547,41 @@ PyDoc_STRVAR(add_doc,
\n
\
This has no effect if the element is already present."
);
static
int
set_contains
(
PySetObject
*
so
,
PyObject
*
key
)
{
PyObject
*
tmpkey
;
int
rv
;
rv
=
set_contains_key
(
so
,
key
);
if
(
rv
==
-
1
)
{
if
(
!
PyAnySet_Check
(
key
)
||
!
PyErr_ExceptionMatches
(
PyExc_TypeError
))
return
-
1
;
PyErr_Clear
();
tmpkey
=
make_new_set
(
&
PyFrozenSet_Type
,
NULL
);
if
(
tmpkey
==
NULL
)
return
-
1
;
set_swap_bodies
((
PySetObject
*
)
tmpkey
,
(
PySetObject
*
)
key
);
rv
=
set_contains
(
so
,
tmpkey
);
set_swap_bodies
((
PySetObject
*
)
tmpkey
,
(
PySetObject
*
)
key
);
Py_DECREF
(
tmpkey
);
}
return
rv
;
}
static
PyObject
*
set_direct_contains
(
PySetObject
*
so
,
PyObject
*
key
)
{
long
result
;
result
=
set_contains
(
so
,
key
);
if
(
result
==
-
1
)
return
NULL
;
return
PyBool_FromLong
(
result
);
}
PyDoc_STRVAR
(
contains_doc
,
"x.__contains__(y) <==> y in x."
);
static
PyObject
*
set_remove
(
PySetObject
*
so
,
PyObject
*
key
)
{
...
...
@@ -1596,51 +1641,6 @@ PyDoc_STRVAR(discard_doc,
\n
\
If the element is not a member, do nothing."
);
static
PyObject
*
set_pop
(
PySetObject
*
so
)
{
PyObject
*
key
;
register
setentry
*
entry
;
register
int
i
=
0
;
assert
(
PyAnySet_Check
(
so
));
if
(
so
->
used
==
0
)
{
PyErr_SetString
(
PyExc_KeyError
,
"pop from an empty set"
);
return
NULL
;
}
/* Set entry to "the first" unused or dummy set entry. We abuse
* the hash field of slot 0 to hold a search finger:
* If slot 0 has a value, use slot 0.
* Else slot 0 is being used to hold a search finger,
* and we use its hash value as the first index to look.
*/
entry
=
&
so
->
table
[
0
];
if
(
entry
->
key
==
NULL
||
entry
->
key
==
dummy
)
{
i
=
(
int
)
entry
->
hash
;
/* The hash field may be a real hash value, or it may be a
* legit search finger, or it may be a once-legit search
* finger that's out of bounds now because it wrapped around
* or the table shrunk -- simply make sure it's in bounds now.
*/
if
(
i
>
so
->
mask
||
i
<
1
)
i
=
1
;
/* skip slot 0 */
while
((
entry
=
&
so
->
table
[
i
])
->
key
==
NULL
||
entry
->
key
==
dummy
)
{
i
++
;
if
(
i
>
so
->
mask
)
i
=
1
;
}
}
key
=
entry
->
key
;
Py_INCREF
(
dummy
);
entry
->
key
=
dummy
;
so
->
used
--
;
so
->
table
[
0
].
hash
=
i
+
1
;
/* next place to start */
return
key
;
}
PyDoc_STRVAR
(
pop_doc
,
"Remove and return an arbitrary set element."
);
static
PyObject
*
set_reduce
(
PySetObject
*
so
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment