UArray(3U)

πŸ’– UArray(3U) πŸ’–

okay bestie so this is a page straight out of the InterViews Reference Manual, and today's main character is UArray β€” the dynamic array class. buckle up, she's iconic πŸŽ€


✨ NAME ✨

UArray β€” dynamic array class πŸ¦‹


🌸 SYNOPSIS 🌸

#include <Unidraw/uarray.h>

πŸ’… DESCRIPTION πŸ’…

So UArray implements a dynamic array, which is literally just an array that grows as elements get added. she's flexible like that πŸ’–

She can also act as a linked list, letting you insert and remove objects β€” no cap. but listen, the overhead for those operations is generally greater than what you'd get from conventional doubly-linked list implementations. so it's giving "you can, but bestie, know the cost" 😭

HOWEVER (and this is the slay) β€” the overhead per stored object is potentially much less for a UArray, and you can access objects by index in constant time. constant time?? we love to see it πŸ‘‘


🫢 PUBLIC OPERATIONS 🫢

  • UArray(int = 16) β€” Create a new UArray instance, and optionally hand her an estimate of its maximum size. specifying the size is not required, but if you supply an accurate estimate, performance improves. so like, a little foresight goes a long way, periodt ✨
  • void*& operator[](int index) β€” Overloading the brackets operator means you can access the UArray's elements with the standard array notation. but heads up bestie: type information is lost when you retrieve objects from the UArray, so you're gonna have to cast. it's giving mystery box energy πŸ™ˆ
  • void Insert(void*, int index) void Remove(int index) β€” Insert and remove an object at a particular index, moving the succeeding objects up or down one position as required. everybody shuffles, that's just the vibe πŸ’ƒ
  • int Index(void*) β€” Return the given object's index in the UArray. if the object doesn't appear in the UArray, you get back -1. sad girl hours, she's just not there 😭
  • int Count() β€” Return the number of objects inserted in the UArray. the headcount, the census, the who's here 🧚
  • void Clear() β€” Clear the UArray, reducing the number of objects it contains to zero. it's giving clean slate, fresh start, reset the timeline 🌈

ngl, that "type information is lost" line in operator[] is the one to tattoo on your brain. cast responsibly, bestie πŸ’€

and that's the whole page, fr fr. this was Unidraw, dated 6 August 1990 β€” yeah she's vintage, she's a classic, she ate and left no crumbs πŸ‘‘πŸ’– bye bestie! πŸŽ€βœ¨