@libp2p/peer-collections
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -22,3 +22,6 @@ import type { PeerId } from '@libp2p/interface-peer-id'; | ||
values(): IterableIterator<PeerId>; | ||
intersection(other: PeerSet): PeerSet; | ||
difference(other: PeerSet): PeerSet; | ||
union(other: PeerSet): PeerSet; | ||
} | ||
//# sourceMappingURL=set.d.ts.map |
@@ -55,3 +55,31 @@ import { peerIdFromString } from '@libp2p/peer-id'; | ||
} | ||
intersection(other) { | ||
const output = new PeerSet(); | ||
for (const peerId of other) { | ||
if (this.has(peerId)) { | ||
output.add(peerId); | ||
} | ||
} | ||
return output; | ||
} | ||
difference(other) { | ||
const output = new PeerSet(); | ||
for (const peerId of this) { | ||
if (!other.has(peerId)) { | ||
output.add(peerId); | ||
} | ||
} | ||
return output; | ||
} | ||
union(other) { | ||
const output = new PeerSet(); | ||
for (const peerId of other) { | ||
output.add(peerId); | ||
} | ||
for (const peerId of this) { | ||
output.add(peerId); | ||
} | ||
return output; | ||
} | ||
} | ||
//# sourceMappingURL=set.js.map |
{ | ||
"name": "@libp2p/peer-collections", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Stores values against a peer id", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0 OR MIT", |
@@ -26,3 +26,3 @@ import type { PeerId } from '@libp2p/interface-peer-id' | ||
[Symbol.iterator] () { | ||
[Symbol.iterator] (): IterableIterator<PeerId> { | ||
return mapIterable<[number, string], PeerId>( | ||
@@ -36,3 +36,3 @@ this.list.entries(), | ||
concat (list: PeerList) { | ||
concat (list: PeerList): PeerList { | ||
const output = new PeerList(this) | ||
@@ -118,3 +118,3 @@ | ||
push (...peerIds: PeerId[]) { | ||
push (...peerIds: PeerId[]): void { | ||
for (const peerId of peerIds) { | ||
@@ -135,3 +135,3 @@ this.list.push(peerId.toString()) | ||
unshift (...peerIds: PeerId[]) { | ||
unshift (...peerIds: PeerId[]): number { | ||
let len = this.list.length | ||
@@ -146,5 +146,5 @@ | ||
get length () { | ||
get length (): number { | ||
return this.list.length | ||
} | ||
} |
@@ -26,11 +26,11 @@ import type { PeerId } from '@libp2p/interface-peer-id' | ||
[Symbol.iterator] () { | ||
[Symbol.iterator] (): IterableIterator<[PeerId, T]> { | ||
return this.entries() | ||
} | ||
clear () { | ||
clear (): void { | ||
this.map.clear() | ||
} | ||
delete (peer: PeerId) { | ||
delete (peer: PeerId): void { | ||
this.map.delete(peer.toString()) | ||
@@ -62,3 +62,3 @@ } | ||
set (peer: PeerId, value: T) { | ||
set (peer: PeerId, value: T): void { | ||
this.map.set(peer.toString(), value) | ||
@@ -76,9 +76,9 @@ } | ||
values () { | ||
values (): IterableIterator<T> { | ||
return this.map.values() | ||
} | ||
get size () { | ||
get size (): number { | ||
return this.map.size | ||
} | ||
} |
@@ -26,19 +26,19 @@ import type { PeerId } from '@libp2p/interface-peer-id' | ||
get size () { | ||
get size (): number { | ||
return this.set.size | ||
} | ||
[Symbol.iterator] () { | ||
[Symbol.iterator] (): IterableIterator<PeerId> { | ||
return this.values() | ||
} | ||
add (peer: PeerId) { | ||
add (peer: PeerId): void { | ||
this.set.add(peer.toString()) | ||
} | ||
clear () { | ||
clear (): void { | ||
this.set.clear() | ||
} | ||
delete (peer: PeerId) { | ||
delete (peer: PeerId): void { | ||
this.set.delete(peer.toString()) | ||
@@ -70,3 +70,3 @@ } | ||
values () { | ||
values (): IterableIterator<PeerId> { | ||
return mapIterable<string, PeerId>( | ||
@@ -79,2 +79,40 @@ this.set.values(), | ||
} | ||
intersection (other: PeerSet): PeerSet { | ||
const output = new PeerSet() | ||
for (const peerId of other) { | ||
if (this.has(peerId)) { | ||
output.add(peerId) | ||
} | ||
} | ||
return output | ||
} | ||
difference (other: PeerSet): PeerSet { | ||
const output = new PeerSet() | ||
for (const peerId of this) { | ||
if (!other.has(peerId)) { | ||
output.add(peerId) | ||
} | ||
} | ||
return output | ||
} | ||
union (other: PeerSet): PeerSet { | ||
const output = new PeerSet() | ||
for (const peerId of other) { | ||
output.add(peerId) | ||
} | ||
for (const peerId of this) { | ||
output.add(peerId) | ||
} | ||
return output | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
36495
653
0