Verse Library verse

01 Snippet

Implements a generic linked list for fast constant time insertions and removals, ideal for object pooling and heavy modifications.

extracted-snippets/community/snippets/ly1l/fortnite-generic-list/01-snippet.verse

# Source URL: https://dev.epicgames.com/community/snippets/ly1l/fortnite-generic-list
# Local doc:  epic-docs/community/snippets/ly1l/fortnite-generic-list.md
  # With UEFN version 41.00, we can now implement parametric classes with variable members.
  # The code below provides a parametric list implementation.
  # As we know, in Verse, adding or removing elements from an array triggers the allocation of a
  # new modified array. When the number of elements is small, the overhead may be acceptable.
  # For larger arrays, however, it can become significant for such a seemingly trivial operation.
  # Lists provide fast O(1) insertion and removal while avoiding large allocations, typically
  # requiring memory only for a single element. Their ideal use case is scenarios where the
  # contents of the collection are not important in a way that would require iteration, but
  # where efficient acquisition and removal are essential (e.g., object pooling).
  ADT<public> := module:
  readable<public>(value_type: type) := interface<computes>:
  GetValue<public>()<reads> : value_type
  modifiable<public>(value_type: type) := interface<computes>:
  SetValue<public>(
  Value: value_type
  )<transacts> : void
  have_next<public>(value_type: type) := interface<computes>:
  TryGetNext<public>()<transacts><decides> : void
  const_iterator<public>(value_type: type) := interface<computes>(
  readable(value_type),
  have_next(value_type)
  ):
  iterator<public>(value_type: type) := interface<computes>(
  const_iterator(value_type),
  modifiable(value_type)
  ):
  List<public> := module:
  # WARNING. Iterators have no concept of ownership. The user must ensure that

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

    Sign in to vote, comment, or suggest an edit. Sign in