ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:69762] [Ruby trunk - Bug #11315] [Open] [PATCH] Add Array#^ for parity with other set-like operations.
       [not found] <redmine.issue-11315.20150628142533@ruby-lang.org>
@ 2015-06-28 14:25 ` 0x0dea+redmine
  2015-06-28 17:03 ` [ruby-core:69763] [Ruby trunk - Bug #11315] " 0x0dea+redmine
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: 0x0dea+redmine @ 2015-06-28 14:25 UTC (permalink / raw)
  To: ruby-core

Issue #11315 has been reported by D.E. Akers.

----------------------------------------
Bug #11315: [PATCH] Add Array#^ for parity with other set-like operations.
https://bugs.ruby-lang.org/issues/11315

* Author: D.E. Akers
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
## 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)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:69763] [Ruby trunk - Bug #11315] [PATCH] Add Array#^ for parity with other set-like operations.
       [not found] <redmine.issue-11315.20150628142533@ruby-lang.org>
  2015-06-28 14:25 ` [ruby-core:69762] [Ruby trunk - Bug #11315] [Open] [PATCH] Add Array#^ for parity with other set-like operations 0x0dea+redmine
@ 2015-06-28 17:03 ` 0x0dea+redmine
  2015-06-28 17:10 ` [ruby-core:69764] " 0x0dea+redmine
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: 0x0dea+redmine @ 2015-06-28 17:03 UTC (permalink / raw)
  To: ruby-core

Issue #11315 has been updated by D.E. Akers.

File array_xor_vodka.patch added

The original implementation did not correctly handle the case of repeated elements occurring an even number of times in the second array. Attached is an updated version which does not present this defect, courtesy of @apeiros and his 50-proof vodka.

----------------------------------------
Bug #11315: [PATCH] Add Array#^ for parity with other set-like operations.
https://bugs.ruby-lang.org/issues/11315#change-53139

* Author: D.E. Akers
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
## 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)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:69764] [Ruby trunk - Bug #11315] [PATCH] Add Array#^ for parity with other set-like operations.
       [not found] <redmine.issue-11315.20150628142533@ruby-lang.org>
  2015-06-28 14:25 ` [ruby-core:69762] [Ruby trunk - Bug #11315] [Open] [PATCH] Add Array#^ for parity with other set-like operations 0x0dea+redmine
  2015-06-28 17:03 ` [ruby-core:69763] [Ruby trunk - Bug #11315] " 0x0dea+redmine
@ 2015-06-28 17:10 ` 0x0dea+redmine
  2015-06-28 17:57 ` [ruby-core:69765] [Ruby trunk - Feature " 0x0dea+redmine
  2015-06-29  5:05 ` [ruby-core:69767] " nobu
  4 siblings, 0 replies; 5+ messages in thread
From: 0x0dea+redmine @ 2015-06-28 17:10 UTC (permalink / raw)
  To: ruby-core

Issue #11315 has been updated by D.E. Akers.

File array_xor_recycle_seen.patch added

I forgot to recycle the `seen` hash. This last fix should finalize the patch, unless there is some very clever way to XOR two arrays without requiring two tables or a second pass through one of the arrays.

----------------------------------------
Bug #11315: [PATCH] Add Array#^ for parity with other set-like operations.
https://bugs.ruby-lang.org/issues/11315#change-53140

* Author: D.E. Akers
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
## 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/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:69765] [Ruby trunk - Feature #11315] [PATCH] Add Array#^ for parity with other set-like operations.
       [not found] <redmine.issue-11315.20150628142533@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2015-06-28 17:10 ` [ruby-core:69764] " 0x0dea+redmine
@ 2015-06-28 17:57 ` 0x0dea+redmine
  2015-06-29  5:05 ` [ruby-core:69767] " nobu
  4 siblings, 0 replies; 5+ messages in thread
From: 0x0dea+redmine @ 2015-06-28 17:57 UTC (permalink / raw)
  To: ruby-core

Issue #11315 has been updated by D.E. Akers.

Tracker changed from Bug to Feature

----------------------------------------
Feature #11315: [PATCH] Add Array#^ for parity with other set-like operations.
https://bugs.ruby-lang.org/issues/11315#change-53141

* 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/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:69767] [Ruby trunk - Feature #11315] [PATCH] Add Array#^ for parity with other set-like operations.
       [not found] <redmine.issue-11315.20150628142533@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2015-06-28 17:57 ` [ruby-core:69765] [Ruby trunk - Feature " 0x0dea+redmine
@ 2015-06-29  5:05 ` nobu
  4 siblings, 0 replies; 5+ messages in thread
From: nobu @ 2015-06-29  5:05 UTC (permalink / raw)
  To: 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/

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-29  4:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-11315.20150628142533@ruby-lang.org>
2015-06-28 14:25 ` [ruby-core:69762] [Ruby trunk - Bug #11315] [Open] [PATCH] Add Array#^ for parity with other set-like operations 0x0dea+redmine
2015-06-28 17:03 ` [ruby-core:69763] [Ruby trunk - Bug #11315] " 0x0dea+redmine
2015-06-28 17:10 ` [ruby-core:69764] " 0x0dea+redmine
2015-06-28 17:57 ` [ruby-core:69765] [Ruby trunk - Feature " 0x0dea+redmine
2015-06-29  5:05 ` [ruby-core:69767] " nobu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).