Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switched simple test to relase 1.1.0, changed addTargets function to acc... #4

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions classes/Flexihash.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,12 @@ public function addTarget($target, $weight=1)

/**
* Add a list of targets.
* @param array $targets
* @param float $weight
* @param array $targets=>$weight
* @chainable
*/
public function addTargets($targets, $weight=1)
public function addTargets($targets)
{
foreach ($targets as $target)
foreach ($targets as $target=>$weight)
{
$this->addTarget($target,$weight);
}
Expand Down
17 changes: 17 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "damijanc/flexihash",
"type" : "library",
"description": "Flexihash is a small PHP library which implements consistent hashing.",
"license": "MIT",
"authors": [
{
"name": "Paul Annesley",
"email": "pda@github.com"
}
],
"version": "1.0.0-dev",
"autoload": {
"classmap" : [ "classes/" ]
}
}

2 changes: 1 addition & 1 deletion lib/simpletest
Submodule simpletest updated from 8838bf to 1c9db3
13 changes: 9 additions & 4 deletions tests/Flexihash/FlexihashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ public function testAddTargetAndGetAllTargets()

public function testAddTargetsAndGetAllTargets()
{
$targets = array('t-a', 't-b', 't-c');
$targets = array('t-a'=>1, 't-b'=>2, 't-c'=>2);
$targets_without_weight = array('t-a', 't-b', 't-c');

$hashSpace = new Flexihash();
$hashSpace->addTargets($targets);
$this->assertEqual($hashSpace->getAllTargets(), $targets);
$this->assertEqual($hashSpace->getAllTargets(), $targets_without_weight);
}

public function testRemoveTarget()
Expand Down Expand Up @@ -74,14 +75,18 @@ public function testHashSpaceRepeatableLookups()
public function testHashSpaceLookupsAreValidTargets()
{
$targets = array();
foreach (range(1,10) as $i) $targets []= "target$i";
foreach (range(1,10) as $i)
{
$targets_without_weight []= "target$i";
$targets ["target$i"]= 1;
}

$hashSpace = new Flexihash();
$hashSpace->addTargets($targets);

foreach (range(1,10 ) as $i)
{
$this->assertTrue(in_array($hashSpace->lookup("r$i"), $targets),
$this->assertTrue(in_array($hashSpace->lookup("r$i"), $targets_without_weight),
'target must be in list of targets');
}
}
Expand Down