Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 14168 invoked from network); 5 Mar 2009 16:45:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Mar 2009 16:45:57 -0000 Received: (qmail 65970 invoked by uid 500); 5 Mar 2009 16:45:54 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 65947 invoked by uid 500); 5 Mar 2009 16:45:54 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 65936 invoked by uid 99); 5 Mar 2009 16:45:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Mar 2009 08:45:54 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of wmertens@cisco.com designates 144.254.15.119 as permitted sender) Received: from [144.254.15.119] (HELO av-tac-bru.cisco.com) (144.254.15.119) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Mar 2009 16:45:45 +0000 X-TACSUNS: Virus Scanned Received: from strange-brew.cisco.com (localhost [127.0.0.1]) by av-tac-bru.cisco.com (8.11.7p3+Sun/8.11.7) with ESMTP id n25GjOb08978 for ; Thu, 5 Mar 2009 17:45:24 +0100 (CET) Received: from dhcp-peg3-cl31144-254-5-156.cisco.com (dhcp-peg3-cl31144-254-5-156.cisco.com [144.254.5.156]) by strange-brew.cisco.com (8.11.7p3+Sun/8.11.7) with ESMTP id n25GjOt02647 for ; Thu, 5 Mar 2009 17:45:24 +0100 (CET) Message-Id: <6E4DC2A7-6EA0-4826-8462-D313180F5751@cisco.com> From: Wout Mertens To: user@couchdb.apache.org In-Reply-To: <07C64F71-EED4-439C-B08C-8B09EB5621FA@cisco.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v930.3) Subject: Re: Obtaining unique values from a view Date: Thu, 5 Mar 2009 17:45:23 +0100 References: <55fad2460903030527r1295a39bl675478e8a9c5266d@mail.gmail.com> <3EA1C6DC-6331-4068-A89C-DBC462D0B890@cisco.com> <55fad2460903030558r34a2d6b9j5eda578f6002cca4@mail.gmail.com> <64BABFD7-8543-4762-B349-688E76ED6DB2@cisco.com> <92E0BD49-BD57-4CBD-B0BD-2A8391C00E81@apache.org> <148EE677-9FB0-413C-B0D1-7B84C3BAF811@cisco.com> <07C64F71-EED4-439C-B08C-8B09EB5621FA@cisco.com> X-Mailer: Apple Mail (2.930.3) X-Virus-Checked: Checked by ClamAV on apache.org On Mar 5, 2009, at 4:59 PM, Wout Mertens wrote: > Actually, I just did some tests around this, and it turns out that > if you always query with group=true, CouchDB never runs the final > rereduce! So based on this, I created this reduce function for reducing a maps emit(key,value) to unique values per key: function(k,v,r) { function unique_inplace(an_array) { var first = 0; var last = an_array.length; // Find first non-unique pair for(var firstb; (firstb = first) < last && ++first < last; ) { if(an_array[firstb] == an_array[first]) { // Start copying, skipping uniques for(; ++first < last; ) { if (!(an_array[firstb] == an_array[first])) { an_array[++firstb] = an_array[first]; } } // firstb is at the last element of the new array ++firstb; an_array.length = firstb; return; } } } if(r) { var arr=[]; for (var i=0; i