Skip to content

Commit

Permalink
remove f-strings to support lower version
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent Wang committed Jul 30, 2019
1 parent e8e270e commit 3de7df5
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions source/hash/consistent_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ def normal_hash(node_count, item_count):
moved_item_count += 0 if _id == new_id else 1

avg_count = item_count / node_count
print(f'Avg item count on node: {avg_count}')
print('Avg item count on node: %.2f' % avg_count)

max_count = max(node_item_count)
over_per = (max_count - avg_count) / avg_count * 100
print(f'Most item node has {over_per:.2f}% over')
print('Most item node has %.2f%% over' % over_per)

min_count = min(node_item_count)
under_per = (min_count - avg_count) / avg_count * 100
print(f'Least item node has {under_per:.2f}% under')
print('Least item node has %.2f%% under' % under_per)

moved_per = moved_item_count / item_count * 100
print(f'Item moved per after add one node: {moved_per:.2f}%')
print('Item moved per after add one node: %.2f%%' % moved_per)


# 一致性Hash算法
Expand Down Expand Up @@ -83,18 +83,18 @@ def consistent_hash(node_count, item_count):
moved_item_count += 0 if _idx == _idx_new else 1

avg_count = item_count / node_count
print(f'Avg item count on node: {avg_count}')
print('Avg item count on node: %.2f' % avg_count)

max_count = max(node_item_count)
over_per = (max_count - avg_count) / avg_count * 100
print(f'Most item node has {over_per:.2f}% over')
print('Most item node has %.2f%% over' % over_per)

min_count = min(node_item_count)
under_per = (min_count - avg_count) / avg_count * 100
print(f'Least item node has {under_per:.2f}% under')
print('Least item node has %.2f%% under' % under_per)

moved_per = moved_item_count / item_count * 100
print(f'Item moved per after add one node: {moved_per:.2f}%')
print('Item moved per after add one node: %.2f%%' % moved_per)


# 一致性Hash算法(虚拟结点)
Expand Down Expand Up @@ -160,15 +160,15 @@ def consistent_hash_vnode(node_count, v, item_count):
moved_item_count += 0 if node_id == node_id_new else 1

avg_count = item_count / node_count
print(f'Avg item count on node: {avg_count}')
print('Avg item count on node: %.2f' % avg_count)

max_count = max(node_item_count)
over_per = (max_count - avg_count) / avg_count * 100
print(f'Most item node has {over_per:.2f}% over')
print('Most item node has %.2f%% over' % over_per)

min_count = min(node_item_count)
under_per = (min_count - avg_count) / avg_count * 100
print(f'Least item node has {under_per:.2f}% under')
print('Least item node has %.2f%% under' % under_per)

moved_per = moved_item_count / item_count * 100
print(f'Item moved per after add one node: {moved_per:.2f}%')
print('Item moved per after add one node: %.2f%%' % moved_per)

0 comments on commit 3de7df5

Please sign in to comment.