From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id ECECB1960015 for ; Mon, 29 Jun 2015 13:40:41 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (smtp.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 85427B5D9BE for ; Mon, 29 Jun 2015 14:05:45 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 20AAF97A82B for ; Mon, 29 Jun 2015 14:05:47 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Authentication-Results: funfun.nagaokaut.ac.jp (amavisd-new); dkim=fail (1024-bit key) reason="fail (message has been altered)" header.d=sendgrid.me Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jvtTarJeaqeW for ; Mon, 29 Jun 2015 14:05:46 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id A1D2497A820 for ; Mon, 29 Jun 2015 14:05:46 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id E05A1952441 for ; Mon, 29 Jun 2015 14:05:44 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 3565912045B; Mon, 29 Jun 2015 14:05:43 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with ESMTPS id 2F9AC12040C for ; Mon, 29 Jun 2015 14:05:39 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=Nkhz1hm9AOT2p6iX98pxXuzIxpE=; b=ukIUwzfAdOkdwqtalC dV8pq6sG4S48qeCh7jimKmFiBGX1ZhMZELLubwAPtBQpwUKNC7oxIhCX/Uzfbz+A 58Wn4lutGOzfNpwEhfq7Hza0/IFS2iMfo3GY0Y5+Q6yQ+qGTpej56BH9we2FYt66 86iE5ZWiWJxTMv0sHE/jrFIQg= Received: by filter-174.sjc1.sendgrid.net with SMTP id filter-174.28507.5590D21925 2015-06-29 05:05:33.015902778 +0000 UTC Received: from herokuapp.com (ec2-54-89-88-59.compute-1.amazonaws.com [54.89.88.59]) by ismtpd-002 (SG) with ESMTP id 14e3db4c076.6c50.66777a for ; Mon, 29 Jun 2015 05:05:32 +0000 (UTC) Date: Mon, 29 Jun 2015 05:05:32 +0000 From: nobu@ruby-lang.org To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 44344 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11315 X-Redmine-Issue-Author: 0x0dea X-Redmine-Sender: nobu X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS4jNdEylUTdAONDSw9Ngkwa1Igkd5QMnaeVBz vz958TahHIPn2v3uMh+MnqsKXu+dfGgNINvsNG2lCwA5m+qjJNu+8w2/ux+XU8rt4dczle/EhtGYnP h18WIrNBhuBk1zE= X-ML-Name: ruby-core X-Mail-Count: 69767 Subject: [ruby-core:69767] [Ruby trunk - Feature #11315] [PATCH] Add Array#^ for parity with other set-like operations. X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #11315 has been updated by Nobuyoshi Nakada. `st_update` does lookup/replace/delete/insert in the callback at once. And your patches are broken, necessary spaces are stripped. ~~~diff diff --git a/array.c b/array.c index 072e30d..737afa3 100644 --- a/array.c +++ b/array.c @@ -4200,6 +4200,14 @@ rb_ary_or(VALUE ary1, VALUE ary2) return ary3; } +static int +ary_hash_xorset(st_data_t *key, st_data_t *value, st_data_t arg, int existing) +{ + if (existing) return ST_DELETE; + *key = *value = (VALUE)arg; + return ST_CONTINUE; +} + /* * call-seq: * ary ^ other_ary -> new_ary @@ -4228,15 +4236,9 @@ rb_ary_xor(VALUE ary1, VALUE ary2) result = ary_make_hash(ary1); for (i = 0; i < RARRAY_LEN(ary2); ++i) { - elt = (st_data_t)RARRAY_AREF(ary2, i); - if (st_lookup(RHASH_TBL_RAW(seen), elt, 0)) continue; - st_update(RHASH_TBL_RAW(seen), elt, ary_hash_orset, elt); - if (st_lookup(RHASH_TBL_RAW(result), elt, 0)) { - st_delete(RHASH_TBL_RAW(result), &elt, 0); - } - else { - st_update(RHASH_TBL_RAW(result), elt, ary_hash_orset, elt); - } + elt = (st_data_t)RARRAY_AREF(ary2, i); + if (!st_update(RHASH_TBL_RAW(seen), elt, ary_hash_orset, elt)) + st_update(RHASH_TBL_RAW(result), elt, ary_hash_xorset, elt); } ary3 = rb_hash_values(result); ~~~ ---------------------------------------- Feature #11315: [PATCH] Add Array#^ for parity with other set-like operations. https://bugs.ruby-lang.org/issues/11315#change-53143 * Author: D.E. Akers * Status: Open * Priority: Normal * Assignee: ---------------------------------------- ## Proposal It is proposed that `Array` be given an "XOR" method which returns the symmetric difference between itself and another array. ## Rationale `#&` and `#|` need a friend to complete the set of set-like operations on `Array`. ---Files-------------------------------- array_xor.patch (2.69 KB) array_xor_vodka.patch (2.97 KB) array_xor_recycle_seen.patch (3 KB) -- https://bugs.ruby-lang.org/