Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

count() and size() returns sum - intentional? #1

Closed
andlaz opened this Issue January 24, 2012 · 7 comments

2 participants

andlaz Nicolas Brousse
andlaz

Given two Judy instances, how can the non-static methods size() and count() on any of the two instances be returning what seems to be the sum of all elements on judy arrays in the same PHP process?

Is this intentional? Nothing seems to be pointing to this in documentation. Did i miss something? See Unit test below. testSizeConsistent() fails, others pass, including testIsSizeSum()

class JudyTest extends PHPUnit_Framework_TestCase {

    private $a, $b;

    public function setUp() {

        $this->a = new Judy(Judy::STRING_TO_MIXED);
        $this->b = new Judy(Judy::STRING_TO_MIXED);
    }

    public function testSizeConsistent() {

        // lets populate a 
        $this->a->offsetSet("foo", "bar");
        $this->a->offsetSet("another", "value");

        // b couldn't have possibly grown?
        $this->assertTrue($this->b->size() === 0);

    }

    public function testSizeZero() {

        $this->assertTrue($this->a->size() === 0);
        $this->assertTrue($this->b->size() === 0);

    }

    public function testIsSizeSum() {

        $this->a->offsetSet("foo", "bar");
        $this->a->offsetSet("another", "value");
        $this->b->offsetSet("third", "..");

        $this->assertTrue($this->b->size() === 3);

    }


}

( i am using the latest "beta" stability Judy array php module from pecl (pecl.php.net/Judy-0.1.2) and the latest libjudy available in macports ( judy @1.0.5 (devel) ) on OS X Lion )

thanks! Andras

ps: i have posted this at http://stackoverflow.com/questions/8973744/php-judy-array-size-count-not-what-it-claims-to-be too, no answers so far - feel free to respond there if this is indeed intentional.

Nicolas Brousse
Owner
orieg commented May 20, 2012

Hi Andreas, i'm just catching up on this. I will check, it definitely sound like a bug.

andlaz
andlaz commented May 20, 2012

much appreciated!

Nicolas Brousse
Owner
orieg commented May 30, 2012

FYI, the issue is only on STRING_TO_MIXED types because of the way the count is done for this specific type. it's using JUDY_G(counter), with an unique counter variable, no matter how many instances are running. Should be an easy fix.

Nicolas Brousse orieg closed this May 30, 2012
Nicolas Brousse
Owner
orieg commented May 30, 2012

This should be fix. Test is now passing. I will plan a bug fix release.

=====================================================================
TIME START 2012-05-30 20:58:33
=====================================================================
PASS Check for Judy presence [tests/001.phpt] 
PASS Check for Judy BITSET set/unset/test methods [tests/bitset_001.phpt] 
PASS Check for Judy BITSET free/count/byCount methods [tests/bitset_002.phpt] 
PASS Check for Judy BITSET first/next/last/prev methods [tests/bitset_003.phpt] 
PASS Check for Judy BITSET firstEmpty/nextEmpty/lastEmpty/prevEmpty methods [tests/bitset_004.phpt] 
PASS Check for Judy BITSET __clone() method [tests/bitset_005.phpt] 
PASS Check for Judy count() method when two instances INT_TO_INT are declared [tests/github_issue1_001.phpt] 
PASS Check for Judy count() method when two instances STRING_TO_MIXED are declared [tests/github_issue1_002.phpt] 
PASS Check for Judy INT_TO_INT set/unset/get methods [tests/int_to_int_001.phpt] 
PASS Check for Judy INT_TO_INT free/count/byCount methods [tests/int_to_int_002.phpt] 
PASS Check for Judy INT_TO_INT first/next/last/prev methods [tests/int_to_int_003.phpt] 
PASS Check for Judy INT_TO_INT firstEmpty/nextEmpty/lastEmpty/prevEmpty methods [tests/int_to_int_004.phpt] 
PASS Check for Judy INT_TO_INT __clone() method [tests/int_to_int_005.phpt] 
PASS Check for Judy INT_TO_MIXED set/unset/get methods [tests/int_to_mixed_001.phpt] 
PASS Check for Judy INT_TO_MIXED free/count/byCount methods [tests/int_to_mixed_002.phpt] 
PASS Check for Judy INT_TO_MIXED first/next/last/prev methods [tests/int_to_mixed_003.phpt] 
PASS Check for Judy INT_TO_INT firstEmpty/nextEmpty/lastEmpty/prevEmpty methods [tests/int_to_mixed_004.phpt] 
PASS Check for Judy INT_TO_MIXED __clone() method [tests/int_to_mixed_005.phpt] 
PASS Check for Error with Judy::__construct() when object has been already instantiated [tests/judy_error.phpt] 
PASS Check for Judy ITERATOR using foreach() [tests/judy_foreach.phpt] 
PASS Check for Judy TYPES using Judy::getType and judy_type() [tests/judy_type.phpt] 
PASS Check for Judy STRING_TO_INT set/unset/get methods [tests/string_to_int_001.phpt] 
PASS Check for Judy STRING_TO_INT free/size methods [tests/string_to_int_002.phpt] 
PASS Check for Judy STRING_TO_INT first/next/last/prev methods [tests/string_to_int_003.phpt] 
PASS Check for Judy STRING_TO_INT __clone() method [tests/string_to_int_004.phpt] 
PASS Check for Judy STRING_TO_MIXED set/unset/get methods [tests/string_to_mixed_001.phpt] 
PASS Check for Judy STRING_TO_MIXED free/size methods [tests/string_to_mixed_002.phpt] 
PASS Check for Judy STRING_TO_MIXED first/next/last/prev methods [tests/string_to_mixed_003.phpt] 
PASS Check for Judy STRING_TO_MIXED __clone() method [tests/string_to_mixed_004.phpt] 
=====================================================================
TIME END 2012-05-30 20:58:36

=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped    :    0
Exts tested     :   60
---------------------------------------------------------------------

Number of tests :   29                29
Tests skipped   :    0 (  0.0%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :    0 (  0.0%) (  0.0%)
Expected fail   :    0 (  0.0%) (  0.0%)
Tests passed    :   29 (100.0%) (100.0%)
---------------------------------------------------------------------
Time taken      :    3 seconds
=====================================================================
andlaz
andlaz commented June 06, 2012

thank you!

Nicolas Brousse
Owner
orieg commented June 07, 2012

You're welcome :)

Nicolas Brousse orieg referenced this issue from a commit May 30, 2012
Fix github issue #1, Ref. #1
git-svn-id: https://svn.php.net/repository/pecl/judy/trunk@325902 c90b9560-bf6c-de11-be94-00142212c4b1
a842e22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.