Skip to content

Commit 5ee98f8

Browse files
authored
Merge pull request #1 from piever/pv/refs
Add refpool
2 parents 56d7603 + fb87d68 commit 5ee98f8

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/DataAPI.jl

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ For a given array `A`, potentially return an optimized "ref array" representatio
2222
original array, which can allow for faster comparison and sorting.
2323
2424
The default definition just returns the input array. This function is useful for custom
25-
array types which already store a "hashed"-like representation of elements where comparison
26-
can be much faster than the original scalar value, like pooled arrays.
25+
array types which already store a "hashed"-like representation of elements where testing
26+
equality or permuting elements in place can be much faster than the original scalar value,
27+
like pooled arrays.
2728
2829
This generic function is owned by DataAPI.jl itself, which is the sole provider of the
2930
default definition.
@@ -35,7 +36,7 @@ refarray(A::AbstractArray) = A
3536
refvalue(A, x)
3637
3738
For the *original* array `A`, and a "ref value" `x` taken from `refarray(A)`, return the
38-
appropriate *original* value.
39+
appropriate *original* value. `refvalue(A, refarray(A)[I...])` must be equal to `A[I...]`.
3940
4041
By default, `refvalue(A, x)` returns `x` (since `refarray(A)` returns `A` by default).
4142
This allows recovering an original array element after operating on the "ref values".
@@ -46,6 +47,22 @@ default definition.
4647
function refvalue end
4748
refvalue(A::AbstractArray, x) = x
4849

50+
"""
51+
refpool(A)
52+
53+
Whenever available, return an indexable object `pool` such that, given the *original* array `A` and
54+
a "ref value" `x` taken from `refarray(A)`, `pool[x]` is the appropriate *original* value. Return
55+
`nothing` i such object is not available. If `refpool(A)` is not `nothing`, then
56+
`refpool(A)[refarray(A)[I...]]` must be equal to `A[I...]`.
57+
58+
By default, `refpool(A)` returns `nothing`.
59+
60+
This generic function is owned by DataAPI.jl itself, which is the sole provider of the
61+
default definition.
62+
"""
63+
function refpool end
64+
refpool(A::AbstractArray) = nothing
65+
4966
"""
5067
nondatavaluetype(T)
5168

0 commit comments

Comments
 (0)