HarlanH/DataFrames.jl — pull request #242 by kmsquire (2013-04-09 19:13:51+00:00)
Title: RFC: Added ref type parameter, `compact` to PooledDataFrame

__[Copied from https://github.com/HarlanH/DataFrames.jl/pull/227; see there for additional comments/discussion. That pull was from my repository, and this one is from the DataFrames.jl repo, which makes it easier for others to test.]__

* Allows the user to specify the reference type for `PooledDataArrays`
(default is still `Uint16`)
* Added `compact` to take an existing `PooledDataArray` and change the
reference type to the smallest size possible. Returns the same
`PooledDataArray` if nothing has changed, and a new one if the size
is reduced

The current `PooledDataArray` tests pass.

Example (from https://github.com/HarlanH/DataFrames.jl/issues/241#issuecomment-16133368)
```julia
julia> using DataFrames

julia> a = PooledDataArray([1,1,2,2])
4-element Int64 PooledDataArray:
1
1
2
2

julia> a.refs
4-element Uint16 Array:
0x0001
0x0001
0x0002
0x0002

julia> b = compact(a)
4-element Int64 PooledDataArray:
1
1
2
2

julia> b.refs
4-element Uint8 Array:
0x01
0x01
0x02
0x02

julia> c = PooledDataArray([1,1,2,2], Uint8)
4-element Int64 PooledDataArray:
1
1
2
2

julia> c.refs
4-element Uint8 Array:
0x01
0x01
0x02
0x02

julia> c = PooledDataArray([1,1,2,2], Int8)
4-element Int64 PooledDataArray:
1
1
2
2

julia> c.refs
4-element Int8 Array:
1
1
2
2
```