UList(3U)

πŸ’– UList β€” the circular doubly-linked list class, bestie πŸ’–

okay so this is UList(3U) from the InterViews Reference Manual, and she's giving classic C++ container realness. buckle up πŸŽ€


✨ SYNOPSIS ✨

#include <Unidraw/ulist.h>

like, that's it. one include. she's low maintenance fr πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so UList implements a circular, doubly-linked list. and the way that works is iconic: the sentinel and each entry in the list are all instances of the UList class. every one of them holds a void pointer to the data they contain, plus pointers to the next and previous UList instance in the list. 🫢

and here's the cute part β€” the sentinel UList instance is considered to represent the list. she is the list. main character energy, no cap πŸ‘‘


🌸 PUBLIC OPERATIONS 🌸

  • UList(void* = nil) β€” create a new UList instance, and optionally hand her the value for the void pointer she stores. ✨
  • virtual ~UList() β€” delete the entire list. normally it's the sentinel (aka the entry that represents the list) that gets deleted explicitly. but heads up bestie: the data on the list, stored as void*'s, cannot be deleted in this manner. so don't come for me when your data leaks, ok? πŸ’€
  • void Append(UList*)
  • void Prepend(UList*) β€” okay so these two hit different depending on who you call them on. when performed on the sentinel, Append appends an element to the end of the list and Prepend prepends it to the beginning of the list. but when performed on a UList instance other than the sentinel, Append has the effect of inserting its argument before the instance, while Prepend has the effect of inserting it after the instance. yes that's flipped, no I did not make that up, it's giving chaotic but we love her πŸ™ˆ
  • void Remove(UList*) β€” unlink the specified UList instance from the list it's in. the object on which this operation is called is irrelevant, so don't stress about which one you're holding, it literally does not matter 🧚
  • void Delete(void*) β€” find the UList instance in this list containing the given void pointer, remove it from the list it's in, and delete it. bye girl πŸ‘‹
  • UList* Find(void*) β€” return the UList instance in this list containing the given void pointer. πŸ”
  • UList* First()
  • UList* Last()
  • UList* End()
  • UList* Next()
  • UList* Prev() β€” return various UList instances in the list relative to this, i.e. as if it were the sentinel. End returns the sentinel (this) and is useful for detecting the end of an iteration through the list; the other operations are self-explanatory. periodt πŸ’…
  • boolean IsEmpty() β€” return whether or not the list has any elements. vibe check πŸ•΅οΈβ™€οΈ
  • void* operator()() β€” return the void pointer that the UList stores. she's got the goods πŸ’–
  • UList* operator[](int i) β€” return the *i*th UList in the list, where the next element is the first, etc. indexing but make it ✨spicy✨

ngl the sentinel-does-everything design is highkey a slay once it clicks. iteration goes First() β†’ Next() β†’ … β†’ End(), and you're done. iykyk 🌈

and that's the whole page, bestie β€” no notes, we ate πŸ“

this was UList(3U) from Unidraw, dated 3 October 1990 πŸ’œ βœ¨πŸŽ€πŸ¦‹