Stop using underscores for "private" methods

Until a decision [1] is made about how to (and if) support private
methods, we should not start doing this ad-hoc. This way we keep the
codebase consistent, instead of different modules using different
approaches.

[1]: #162
parent e0a458d4
Pipeline #99302170 passed with stages
in 15 minutes and 26 seconds
......@@ -232,7 +232,7 @@ object Map!(K: Hash + Equal, V) {
#
# map.remove('name') # => 'Alice'
def remove(key: K) -> ?V {
let index = _bucket_index(key)
let index = bucket_index(key)
index.if_false {
return
......@@ -243,7 +243,7 @@ object Map!(K: Hash + Equal, V) {
@buckets[index!] = Nil
@length -= 1
_backwards_shift(index! + 1)
backwards_shift(index! + 1)
pair.value
}
......@@ -359,7 +359,7 @@ object Map!(K: Hash + Equal, V) {
# map.key?('name') # => True
# map.key?('city') # => False
def key?(key: K) -> Boolean {
_bucket_index(key).if(true: { True }, false: { False })
bucket_index(key).if(true: { True }, false: { False })
}
# Inserts the key and value in this `Map`, returning the `Map` itself.
......@@ -377,7 +377,7 @@ object Map!(K: Hash + Equal, V) {
rehash
}
_insert_pair(Pair.new(key: key, value: value, hash: _hash_key(key)))
insert_pair(Pair.new(key: key, value: value, hash: hash_key(key)))
self
}
......@@ -394,13 +394,13 @@ object Map!(K: Hash + Equal, V) {
old_buckets.each_with_index do (pair, index) {
pair.if_true {
pair.reset_distance
_rehash_pair(pair!)
rehash_pair(pair!)
}
}
}
# Hashes the supplied key using the internal hasher of this `Map`.
def _hash_key(key: K) -> Integer {
def hash_key(key: K) -> Integer {
let hasher = @random_state.to_hasher
key.hash(hasher)
......@@ -412,8 +412,8 @@ object Map!(K: Hash + Equal, V) {
#
# The `Pair` to insert must be pre-hashed using the `Hasher` used internally
# by this `Map`, otherwise it might not be retrieved later.
def _insert_pair(mut pair: Pair!(K, V)) {
let mut index = _desired_bucket(pair.hash)
def insert_pair(mut pair: Pair!(K, V)) {
let mut index = desired_bucket(pair.hash)
{
let existing = @buckets[index]
......@@ -436,14 +436,14 @@ object Map!(K: Hash + Equal, V) {
pair = existing!
}
index = _desired_bucket(index + 1)
index = desired_bucket(index + 1)
pair.increase_distance
}.loop
}
# Rehashes an existing pair into the list of buckets.
def _rehash_pair(mut pair: Pair!(K, V)) {
let mut index = _desired_bucket(pair.hash)
def rehash_pair(mut pair: Pair!(K, V)) {
let mut index = desired_bucket(pair.hash)
{
let existing = @buckets[index]
......@@ -459,20 +459,20 @@ object Map!(K: Hash + Equal, V) {
pair = existing!
}
index = _desired_bucket(index + 1)
index = desired_bucket(index + 1)
pair.increase_distance
}.loop
}
# Returns the desired bucket index for the given hash.
def _desired_bucket(hash: Integer) -> Integer {
def desired_bucket(hash: Integer) -> Integer {
hash % @capacity
}
# Returns the index of the bucket the key resides in.
def _bucket_index(key: K) -> ?Integer {
let hash = _hash_key(key)
let mut index = _desired_bucket(hash)
def bucket_index(key: K) -> ?Integer {
let hash = hash_key(key)
let mut index = desired_bucket(hash)
let desired = index
let mut pair = @buckets[index]
......@@ -491,7 +491,7 @@ object Map!(K: Hash + Equal, V) {
return
}
index = _desired_bucket(index + 1)
index = desired_bucket(index + 1)
(index == desired).if_true {
# We cycled through all buckets but didn't find a matching pair.
......@@ -505,7 +505,7 @@ object Map!(K: Hash + Equal, V) {
}
# Shifts all pairs to the left starting at the given bucket index.
def _backwards_shift(mut index: Integer) {
def backwards_shift(mut index: Integer) {
let mut pair = @buckets[index]
{ pair.and { pair!.distance.positive? } }.while_true {
......@@ -573,7 +573,7 @@ impl Index!(K, V) for Map!(K, V) {
#
# map['name'] # => 'Alice'
def [](key: K) -> ?V {
let index = _bucket_index(key)
let index = bucket_index(key)
index.if(true: { @buckets[index!].value }, false: { Nil })
}
......
......@@ -34,7 +34,7 @@ let _IPV6_STRING_MAXIMUM_LENGTH = 45
let _IPV4_TO_IPV6_SHIFT = 8
# Converts a pair of IPv4 octets into a single IPv6 hextet.
def _octets_to_hextet(first: Integer, second: Integer) -> Integer {
def octets_to_hextet(first: Integer, second: Integer) -> Integer {
first << _IPV4_TO_IPV6_SHIFT | second
}
......@@ -389,8 +389,8 @@ impl IpAddress for Ipv6Address {
}
(ipv4_segments.length == _IPV4_OCTETS).if_true {
segments[6] = _octets_to_hextet(ipv4_segments[0]!, ipv4_segments[1]!)
segments[7] = _octets_to_hextet(ipv4_segments[2]!, ipv4_segments[3]!)
segments[6] = octets_to_hextet(ipv4_segments[0]!, ipv4_segments[1]!)
segments[7] = octets_to_hextet(ipv4_segments[2]!, ipv4_segments[3]!)
}
(segments.length == _IPV6_HEXTETS).if_false {
......@@ -826,8 +826,8 @@ impl IpAddress for Ipv4Address {
0,
0,
0,
_octets_to_hextet(@segments[0]!, @segments[1]!),
_octets_to_hextet(@segments[2]!, @segments[3]!),
octets_to_hextet(@segments[0]!, @segments[1]!),
octets_to_hextet(@segments[2]!, @segments[3]!),
)
}
......@@ -840,8 +840,8 @@ impl IpAddress for Ipv4Address {
0,
0,
_IPV6_HEXTET_MAXIMUM,
_octets_to_hextet(@segments[0]!, @segments[1]!),
_octets_to_hextet(@segments[2]!, @segments[3]!),
octets_to_hextet(@segments[0]!, @segments[1]!),
octets_to_hextet(@segments[2]!, @segments[3]!),
)
}
}
......
......@@ -233,12 +233,12 @@ object Socket {
# Returns the local address of this socket.
def local_address !! IoError -> SocketAddress {
try _socket_address(self)
try socket_address(self)
}
# Returns the peer address of this socket.
def peer_address !! IoError -> SocketAddress {
try _socket_address(socket: self, peer: True)
try socket_address(socket: self, peer: True)
}
# Returns the value of the `IP_TTL` option.
......@@ -503,8 +503,8 @@ object UdpSocket {
#
# try! UdpSocket.new(ip: Ipv4Address.new(0, 0, 0, 0), port: 0)
def init(ip: ToIpAddress, port: Integer) !! IoError {
let ip_addr = try _to_ip_address(ip)
let domain = _domain_for_ip(ip_addr)
let ip_addr = try to_ip_address(ip)
let domain = domain_for_ip(ip_addr)
@socket = try Socket.new(domain: domain, kind: DGRAM)
......@@ -623,8 +623,8 @@ object TcpStream {
#
# try! TcpStream.new(ip: '127.0.0.1', port: 40_000)
def init(ip: ToIpAddress, port: Integer) !! IoError {
let ip_addr = try _to_ip_address(ip)
let domain = _domain_for_ip(ip_addr)
let ip_addr = try to_ip_address(ip)
let domain = domain_for_ip(ip_addr)
@socket = try Socket.new(domain: domain, kind: STREAM)
......@@ -737,8 +737,8 @@ object TcpListener {
backlog = MAXIMUM_LISTEN_BACKLOG,
only_ipv6 = False
) !! IoError {
let ip_addr = try _to_ip_address(ip)
let domain = _domain_for_ip(ip_addr)
let ip_addr = try to_ip_address(ip)
let domain = domain_for_ip(ip_addr)
@socket = try Socket.new(domain: domain, kind: STREAM)
......@@ -802,7 +802,7 @@ impl Close for TcpListener {
}
# Obtains the local or peer address of a socket.
def _socket_address(socket: Socket, peer = False) !! IoError -> SocketAddress {
def socket_address(socket: Socket, peer = False) !! IoError -> SocketAddress {
let addr = try bits.address(socket: socket, peer: peer)
let ip = try! ip.parse(addr[0] as String)
......@@ -810,7 +810,7 @@ def _socket_address(socket: Socket, peer = False) !! IoError -> SocketAddress {
}
# Converts a `ToIpAddress` to a `IpAddress`
def _to_ip_address(ip: ToIpAddress) !! IoError -> IpAddress {
def to_ip_address(ip: ToIpAddress) !! IoError -> IpAddress {
try {
ip.to_ip_address
} else (error) {
......@@ -819,6 +819,6 @@ def _to_ip_address(ip: ToIpAddress) !! IoError -> IpAddress {
}
# Returns the domain (IPV4 or IPV6) to use for an IP address.
def _domain_for_ip(ip: IpAddress) -> Integer {
def domain_for_ip(ip: IpAddress) -> Integer {
ip.v6?.if(true: { IPV6 }, false: { IPV4 })
}
......@@ -190,8 +190,8 @@ test.group('std::map::Map.rehash') do (g) {
let pair2 = Pair.new(key: 'b', value: 'value', hash: 1)
map.rehash
map._insert_pair(pair: pair1)
map._insert_pair(pair: pair2)
map.insert_pair(pair: pair1)
map.insert_pair(pair: pair2)
# Moving the pair to a bucket it shouldn't be in allows us to test if
# `resize` ends up moving pairs or not.
......@@ -211,12 +211,12 @@ test.group('std::map::Map.rehash') do (g) {
}
}
test.group('std::map::Map._insert_pair') do (g) {
test.group('std::map::Map.insert_pair') do (g) {
g.test('Inserting a Pair into a Map') {
let map = Map.new
let pair = Pair.new(key: 'key', value: 'value', hash: 0)
map._insert_pair(pair)
map.insert_pair(pair)
assert.equal(map.length, 1)
assert.equal(map.buckets[0], pair)
......@@ -228,8 +228,8 @@ test.group('std::map::Map._insert_pair') do (g) {
let pair2 = Pair.new(key: 'b', value: 'b', hash: 0)
map.rehash
map._insert_pair(pair1)
map._insert_pair(pair2)
map.insert_pair(pair1)
map.insert_pair(pair2)
assert.equal(map.buckets[0], pair1)
assert.equal(map.buckets[1], pair2)
......@@ -244,8 +244,8 @@ test.group('std::map::Map._insert_pair') do (g) {
let pair2 = Pair.new(key: 'a', value: 'b', hash: 0)
map.rehash
map._insert_pair(pair1)
map._insert_pair(pair2)
map.insert_pair(pair1)
map.insert_pair(pair2)
assert.equal(map.buckets[0], pair2)
}
......@@ -256,13 +256,13 @@ test.group('std::map::Map._insert_pair') do (g) {
let pair2 = Pair.new(key: 'two', value: 2, hash: -9161411174267222279)
let pair3 = Pair.new(key: 'three', value: 3, hash: 902578265635837404)
map._insert_pair(pair1)
map.insert_pair(pair1)
map.rehash
map._insert_pair(pair2)
map.insert_pair(pair2)
map.rehash
map._insert_pair(pair3)
map.insert_pair(pair3)
assert.equal(map.buckets[0], pair3)
assert.equal(map.buckets[1], pair2)
......@@ -293,8 +293,8 @@ test.group('std::map::Map.remove') do (g) {
let pair2 = Pair.new(key: 'b', value: 'b', hash: 0)
map.rehash
map._insert_pair(pair1)
map._insert_pair(pair2)
map.insert_pair(pair1)
map.insert_pair(pair2)
map.remove(pair1.key)
assert.equal(map.buckets[0], pair2)
......@@ -397,8 +397,8 @@ test.group('std::map::Map.iter') do (g) {
let pair2 = Pair.new(key: 'b', value: 'value', hash: 1)
map.rehash
map._insert_pair(pair: pair1)
map._insert_pair(pair: pair2)
map.insert_pair(pair: pair1)
map.insert_pair(pair: pair2)
map.rehash
# At this point the bucket layout is: [pair, pair, Nil, Nil]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment