Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
1e71c534
Kaydet (Commit)
1e71c534
authored
May 15, 2014
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #20826: Optimize ipaddress.collapse_addresses().
üst
824db30b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
27 deletions
+28
-27
ipaddress.py
Lib/ipaddress.py
+26
-27
NEWS
Misc/NEWS
+2
-0
No files found.
Lib/ipaddress.py
Dosyayı görüntüle @
1e71c534
...
...
@@ -253,7 +253,7 @@ def summarize_address_range(first, last):
break
def
_collapse_addresses_
recursive
(
addresses
):
def
_collapse_addresses_
internal
(
addresses
):
"""Loops through the addresses, collapsing concurrent netblocks.
Example:
...
...
@@ -263,7 +263,7 @@ def _collapse_addresses_recursive(addresses):
ip3 = IPv4Network('192.0.2.128/26')
ip4 = IPv4Network('192.0.2.192/26')
_collapse_addresses_
recursive
([ip1, ip2, ip3, ip4]) ->
_collapse_addresses_
internal
([ip1, ip2, ip3, ip4]) ->
[IPv4Network('192.0.2.0/24')]
This shouldn't be called directly; it is called via
...
...
@@ -277,28 +277,29 @@ def _collapse_addresses_recursive(addresses):
passed.
"""
while
True
:
last_addr
=
None
ret_array
=
[]
optimized
=
False
for
cur_addr
in
addresses
:
if
not
ret_array
:
last_addr
=
cur_addr
ret_array
.
append
(
cur_addr
)
elif
(
cur_addr
.
network_address
>=
last_addr
.
network_address
and
cur_addr
.
broadcast_address
<=
last_addr
.
broadcast_address
):
optimized
=
True
elif
cur_addr
==
list
(
last_addr
.
supernet
()
.
subnets
())[
1
]:
ret_array
[
-
1
]
=
last_addr
=
last_addr
.
supernet
()
optimized
=
True
else
:
last_addr
=
cur_addr
ret_array
.
append
(
cur_addr
)
addresses
=
ret_array
if
not
optimized
:
return
addresses
# First merge
to_merge
=
list
(
addresses
)
subnets
=
{}
while
to_merge
:
net
=
to_merge
.
pop
()
supernet
=
net
.
supernet
()
existing
=
subnets
.
get
(
supernet
)
if
existing
is
None
:
subnets
[
supernet
]
=
net
elif
existing
!=
net
:
# Merge consecutive subnets
del
subnets
[
supernet
]
to_merge
.
append
(
supernet
)
# Then iterate over resulting networks, skipping subsumed subnets
last
=
None
for
net
in
sorted
(
subnets
.
values
()):
if
last
is
not
None
:
# Since they are sorted, last.network_address <= net.network_address
# is a given.
if
last
.
broadcast_address
>=
net
.
broadcast_address
:
continue
yield
net
last
=
net
def
collapse_addresses
(
addresses
):
...
...
@@ -347,15 +348,13 @@ def collapse_addresses(addresses):
# sort and dedup
ips
=
sorted
(
set
(
ips
))
nets
=
sorted
(
set
(
nets
))
while
i
<
len
(
ips
):
(
first
,
last
)
=
_find_address_range
(
ips
[
i
:])
i
=
ips
.
index
(
last
)
+
1
addrs
.
extend
(
summarize_address_range
(
first
,
last
))
return
iter
(
_collapse_addresses_recursive
(
sorted
(
addrs
+
nets
,
key
=
_BaseNetwork
.
_get_networks_key
)))
return
_collapse_addresses_internal
(
addrs
+
nets
)
def
get_mixed_type_key
(
obj
):
...
...
Misc/NEWS
Dosyayı görüntüle @
1e71c534
...
...
@@ -84,6 +84,8 @@ Core and Builtins
Library
-------
- Issue #20826: Optimize ipaddress.collapse_addresses().
- Issue #21487: Optimize ipaddress.summarize_address_range() and
ipaddress.{IPv4Network,IPv6Network}.subnets().
...
...
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