eclipse-collections icon indicating copy to clipboard operation
eclipse-collections copied to clipboard

Implement new type of collections: Table

Open jolkdarr opened this issue 7 years ago • 8 comments

Hi

That would be nice if the framework did offer Tables. Tables are a kind of map of maps of objects with two key generic types (ROW and COLUMN) and a value generic type (VALUE). For instance, a table MutableIntShortObjectTable<V> could be used instead of a MutableIntObjectMap<MutableShortObjectMap<V>> with removeRow , removeColumn... methods.

Of course, it's a huge work and I might contribute if the feature gets planned.

(I didn't check whether the proposal had ever been registered or not. Sorry if it had).

jolkdarr avatar Mar 11 '18 18:03 jolkdarr

Table is fine to add on the object side. However, we will not add a PrimitiveTable due to the number of permutations between the primitives which are required. These permutations end up inflating the jar. We faced a similar inflation when PrimitiveMaps were implemented. We would be happy to take this contribution 😄 Addition of new data structures can be done with a minor release. For 2018 the release plan is 9.2.0 in April and 10.0.0 in October.

nikhilnanivadekar avatar Mar 18 '18 03:03 nikhilnanivadekar

Hi

I agree with you: the library fatness shall be mastered. However, I think that a single primitive table class (like IntIntTable) would be useful by covering many use cases in addition of a general class.

Very cool if the extension were available in October release. :+1:

jolkdarr avatar Mar 22 '18 08:03 jolkdarr

Hi @jolkdarr for starters the Object Table will cover the boxed primitives condition, so that will be a good place to start. Best way to get it as a part of release is to contribute the feature 😄 . We will be delighted to take this contribution 👍 .

nikhilnanivadekar avatar Mar 22 '18 17:03 nikhilnanivadekar

I've been mulling this over and honestly, I'm not sure what data structure you're proposing. Do just want a map of maps, aka a sparse 2-D array? Do you want a compact 2-D array? Do you want a Map<Tuple<Row,Column>, V>? Do you want a Map<Row, Record> where Record is a (compact) List that has an associated column-name for numbered entries?

gs-rezaem avatar Mar 22 '18 17:03 gs-rezaem

Hi Sorry if I weren't precise enough about the data structure. I had in mind something that could somehow replace the Table class from Guava library which I'm still required to import in my current application (~10000 classes loaded!). API that I'm using is described at: https://google.github.io/guava/releases/19.0/api/docs/com/google/common/collect/Table.html

jolkdarr avatar Mar 22 '18 18:03 jolkdarr

Can you tell us about how you use this api and whether your data is sparse or not? Specifically, do you use the columnMap() or cellSet()? The guava variant doesn't have removeRow, removeColumn. Do you want those?

gs-rezaem avatar Mar 22 '18 18:03 gs-rezaem

  • [x] As mentioned above, Tables could be implemented with maps of maps. Therefore, sparseness doesn't matter.
  • [x] Yes, I'm using rowMap, columnMap and cellSet for iteration purposes.
  • [x] Row/column removal is supported but not explicit (see row and column methods). You should read the logs related to the following issue: https://github.com/google/guava/issues/2716

Interesting as well: https://github.com/google/guava/wiki/NewCollectionTypesExplained#table

jolkdarr avatar Mar 22 '18 18:03 jolkdarr

Putting a sparse dataset into a non-sparse collection is a bad idea from both a time and space perspective. It is literally twice as bad when you have two key dimensions. Guava has ArrayTable and HashBasedTable because of that.

A row-major map of maps also has terrible performance (O(R), not O(1)) for column based operations. I'd be careful with any such usage.

Reading the allowed and disallowed operations on ArrayTable and HashBasedTable, I'm left with the feeling that the Table contract is potentially a bad abstraction, except for the read-only bits, and only if the usage is not performance sensitive. E.g. ArrayTable doesn't allow any remove of any kind, iterator.remove is not supported in any implementation for column views, etc.

Do you just need a HashRowMajorTable aka Map<Row, Map<Col, V>> with convenience methods that are not O(1)?

gs-rezaem avatar Mar 22 '18 19:03 gs-rezaem