tristanls/k-bucket

distance as paramter (like arbiter)

Closed this issue · 10 comments

It should make KBucket more flexible. Thoughts?

Technically, since we're in JavaScript, and distance is only used via KBucket.distance, it's already parametrizable via monkey patching. For example:

const KBucket = require("k-bucket");
KBucket.distance = () => Math.random() * 100;

Heh.. I think this highlights the inconsistency of the API though :)

Yes, it will work, but what if we have 2 buckets and want 2 different algorithms for distance?

I agree, parameterized distance would be a way to do that. You are using buckets with 2 different distance algorithms?

You are using buckets with 2 different distance algorithms?

No.. it's just abstract example.

I think a parameterized distance would make the KBucket API more consistent with itself.

I have some edits I'll promote soon for you to take a look at.

@fanatid here's what I'm thinking. It'll keep the API the same, while incorporating your change, and making the API more self-consistent by exposing KBucket.arbiter: eb85f46

This also makes next version 3.1.0 instead of 4.0.0.

@tristanls it's really cool!

K, thank you for the feedback. Releasing 3.1.0.