Skip to content

Backport of Android's ArraySet implementation that supports API 14+

Notifications You must be signed in to change notification settings

ZacSweers/ArraySetBackport

Repository files navigation

DEPRECATED: ArraySet is now in the support library as of 25.1.0

ArraySetBackport

Backport of the ArraySet implementation from Android Marshmallow. Functionally, it's nearly identical to the original code, with some minor tweaks to use the same structure that ArrayMap uses to support older version.

My hope is that Google will eventually put ArraySet in the support library like they did with ArrayMap.

Usage

(From the AOSP documentation)

ArraySet is a generic set data structure that is designed to be more memory efficient than a traditional HashSet. The design is very similar to ArrayMap, with all of the caveats described there. This implementation is separate from ArrayMap, however, so the Object array contains only one item for each entry in the set (instead of a pair for a mapping).

Note that this implementation is not intended to be appropriate for data structures that may contain large numbers of items. It is generally slower than a traditional HashSet, since lookups require a binary search and adds and removes require inserting and deleting entries in the array. For containers holding up to hundreds of items, the performance difference is not significant, less than 50%.

Because this container is intended to better balance memory use, unlike most other standard Java containers it will shrink its array as items are removed from it. Currently you have no control over this shrinking -- if you set a capacity and then remove an item, it may reduce the capacity to better match the current size. In the future an explicit call to set the capacity should turn off this aggressive shrinking behavior.

Download

compile 'io.sweers.arraysetbackport:arraysetbackport:1.0.0'

Snapshots of the development version are available in Sonatype's snapshots repository.

License

Copyright (C) 2016 Zac Sweers

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Backport of Android's ArraySet implementation that supports API 14+

Resources

Stars

Watchers

Forks

Packages

No packages published