flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

[Java] Shallow equality on `Table`

Open mpdn opened this issue 2 years ago • 1 comments

I have a situation where:

  • I have a flatbuffer input that may be a DAG (i.e. table entries may be referenced multiple times in the input)
  • I want to compute something for every node (i.e. each table entry) in the DAG
  • I want to cache that computation, such that if a table entry is referenced multiple times I only do the computation for that object once.

But FlatBuffers does not seem to have a way of identifying when two instances actually refer to the same underlying data, so this isn't really possible right now.

Note that I do not want deep equality here, as that would mean quadratic time complexity where shallow would be linear.

I think something like shallowEquals on Table could make sense to support such a use case. Basically just checking if bb_pos, vtable_start, vtable_size are equal and bb references the same byte buffer.

shallowHashCode could likewise be implemented to support it being used in a hashmap.

I'm willing to make a PR if this approach seems sensible.

mpdn avatar Dec 19 '23 08:12 mpdn

.

known-samy avatar Dec 19 '23 11:12 known-samy

This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

github-actions[bot] avatar Jun 18 '24 20:06 github-actions[bot]

This issue was automatically closed due to no activity for 6 months plus the 14 day notice period.

github-actions[bot] avatar Jul 02 '24 20:07 github-actions[bot]