搜尋此網誌

2025年12月9日星期二

English with Maggie

Would you do it for me?

比較像在問意願。

Could you do it for me?

比較像在問能力。


Regular verbs +ed 變過去式

used /use-d/ but not /use-凸/

"ed"的三個發音: /id/ /t/ /d/

/t/ /d/ consonants 收尾用 /id/ 相對大聲

wanted: /wan-tid/

needed: /nee-did/

decided: /de-cai-did/


voiced sound:

l, n, r, b, g, m, z

令 vocal cords 震動

called: /call-d/ but not /call-凸/

cleaned: /clean-d/ but not /clean-凸/

offered: /offer-d/ but not /offer-凸/

loved: /love-d/


voiceless sound:

f, s, th, ch, sh, p, k

不令 vocal cords 震動

stopped: /stop-t/ 而不是 /stop-凸/

looked: /look-t/

helped: /help-t/

喀布爾

2025年12月8日星期一

Containers and Adapters

In C++ STL, sequence containers are data structures that store elements in a linear order, allowing sequential access. The main sequence containers are: array, vector, deque, list, and forward_list.

iteration: the process of repeating a mathematical or computing process or set of instructions again and again, each time applying it to the result of the previous stage

dribble (something) (+ adv./prep.) (in football (soccer) and some other sports) to move the ball along with several short kicks, hits or bounces


for (const auto& action : recentActions)

The above line is a range-based for loop in C++.

for → Starts the loop.

const auto& action

    auto deduces the type of each element in recentActions.

    & means we’re iterating by reference (no copy is made).

    const ensures the element cannot be modified inside the loop.

: recentActions → The container we’re iterating over (e.g., std::vector, std::list, etc.).

deduce: to form an opinion about something based on the information or evidence that is available

recentActions is the container (e.g., std::vector, std::list, etc.) that holds multiple elements.

action is a reference to each individual element inside recentActions as the loop iterates.


In C++, std::list is a sequence container implemented as a doubly linked list. It allows fast insertions and deletions anywhere in the sequence but does not support random access like arrays or vectors.


In C++, associative containers are part of the Standard Template Library (STL) that store elements in a way that allows fast retrieval based on keys rather than positions. The main ordered associative containers are: set, multiset, map, and multimap.


Defined in the <set> header as std::set<T>.

Stores unique elements in a sorted order.

Internally implemented as a balanced binary search tree (usually a Red-Black Tree).

Provides logarithmic time complexity (O(log n)) for insertion, deletion, and search.


A side-scrolling video game (alternatively side-scroller) is a video game viewed from a side-view camera angle where the screen follows the player as they move left or right.


The dot (.) operator in C++ is one of the fundamental operators used for member access.

The dot operator (.) is used to access members (variables, functions, or nested types) of an object, struct, or class directly.

It works when you have an object (not a pointer).


The std::pair class in C++ is a simple but powerful utility that lets you store two values together as a single unit. It’s defined in the <utility>  header.

std::pair<std::string, int> playerStats("Alice", 75);

The above line of code is creating a std::pair object named playerStats with two values:

first"Alice" (a std::string)

second75 (an int)


Defined in the <map> header as std::map<Key,T>.

Stores key–value pairs where:

    Key → unique identifier.

    Value (T) → data associated with the key.

Internally implemented as a balanced binary search tree (usually a Red-Black Tree).

Keys are always kept in sorted order (by default using std::less<Key>).


In C++, unordered containers are part of the STL that store elements in hash tables rather than sorted trees. They provide average constant-time (O(1)) performance for insertion, deletion, and lookup, but do not maintain any order of elements.


Container adapters are special containers that provide a restricted interface built on top of other sequence containers (like deque, list, or vector).

They don’t store elements in a unique way themselves; instead, they adapt existing containers to provide specific behaviors.

Defined in the <queue> and <stack> headers.


Last in First out

It’s a data access principle used in computer science and programming.

Think of it like a stack of plates: the last plate you put on top is the first one you take off.

In C++, this principle is implemented using the std::stack container adapter.

empty()

Checks whether the stack has any elements.

top()

Returns a reference to the top element of the stack (the last pushed element).

Does not remove the element.

pop()

Removes the top element from the stack. 


FIFO is the opposite of LIFO (Last In, First Out).

Think of it like a line at a store: the first person to enter the line is the first person served.

In C++, FIFO is implemented using the std::queue container adapter.

front() gives you a reference to the first element in the container.

Does not remove the element (unlike pop() in a queue).

Undefined behavior if called on an empty container (so always check with empty() first).


Defined in the <queue> header as std::priority_queue.

Stores elements in a way that the highest priority element is always accessible at the top.

Internally implemented using a heap structure (by default, a max-heap built on top of a std::vector).

std::priority_queue<int> aiTasks;

std::priority_queue → A priority queue of integers.

aiTasks → The variable name.

By default, std::priority_queue is a max-heap, meaning the largest integer will always be at the top.


In C++ STL, container adapters are special wrappers that provide a specialized interface on top of existing sequence containers (like deque, list, or vector). Instead of exposing all the operations of the underlying container, they restrict and tailor the interface to enforce a particular usage pattern.


Microsoft Copilot

Overview of STL

In C++’s Standard Template Library (STL), containers store data, iterators traverse it, algorithms process it, and functors customize operations.

In computer science, traversing means systematically visiting every element in a data structure (like an array, list, tree, or graph) to access, process, or use the data, often using loops or specific algorithms (Depth-First Search, Breadth-First Search) to move from one element to the next, ensuring each item is handled.

Overloading the parenthesis operator () in computer science, particularly in C++, allows an object of a class to be called or used as if it were a function. This is also referred to as creating a "functor" or "function object."

Microsoft Copilot
Google AI overview

錯則勿憚改

The axiom that you learn more from your failures than your successes is trite but absolutely true.


oversee: to watch somebody/something and make sure that a job or an activity is done correctly

TRW: Transformer Repairing Works

venture: a business project or activity, especially one that involves taking risks

tangle: a twisted mass of threads, hair, etc. that cannot be easily separated

omnivorous: having wide interests in a particular area or activity

prospect: the chances of being successful

desperate: feeling or showing that you have little hope and are ready to do anything without worrying about danger to yourself or others

gig: (especially North American English, informal) a job, especially a temporary one

Sherwood Forest, in Nottinghamshire, England, is a legendary ancient woodland famous as the legendary hideout of the outlaw hero Robin Hood and home to Europe's largest collection of ancient oaks, like the iconic Major Oak.

outrun: to run faster or further than somebody/something

lava: hot liquid rock that comes out of a volcano

Krakatoa, volcano on Rakata Island in the Sunda Strait between Java and Sumatra, Indonesia. Its explosive eruption in 1883 was one of the most catastrophic in history.

A power grid is the interconnected network that generates, transmits, and distributes electricity from power plants to consumers, featuring generation, high-voltage transmission lines, substations (to adjust voltage), and local distribution networks.

scramble: to move quickly, especially with difficulty, using your hands to help you

Grand Coulee is an ancient river bed in the US state of Washington.

literally: exactly

DEC: Digital Equipment Corporation

sift: to examine something very carefully in order to decide what is important or useful or to find something important

deluge: a large number of things that happen or arrive at the same time

downtime: the time during which a machine, especially a computer, is not working

crank up: to make a machine, etc. work or work at a higher level

diner: (in the US) a small, usually cheap, restaurant

baseload: the permanent minimum load that a power supply system is required to deliver

churn out: to produce something quickly and in large amounts

testament: a thing that shows that something else exists or is true

seasoned: (of a person) having a lot of experience of a particular activity

maniac: behaving in an extremely dangerous, violent, wild or crazy way

close-cropped: (of hair, grass, etc.) cut very short

glitch: a small problem or fault that stops something working successfully

haunted: (of an expression on somebody’s face) showing that somebody is very worried

fiasco: something that does not succeed, often in a way that makes people feel embarrassed

origami: the Japanese art of folding paper into attractive shapes

vigilant: alert, watchful

axiom: a rule or principle that most people believe to be true

trite: (of a remark, an opinion, etc.) boring because it has been expressed so many times before; not original


Bill Gates "Source Code"

Online Dictionaries Used:

hk.dictionary.search.yahoo.com

www.oxfordlearnersdictionaries.com

Google AI overview

www.britannica.com

2025年12月2日星期二

Template class

GameEntity(T xPos, T yPos) : x(xPos), y(yPos) {}

That’s a constructor definition in C++ using an initializer list.

GameEntity(T xPos, T yPos)

This is the constructor for the class GameEntity. It takes two parameters of type T (likely a template type, e.g., int, float, or double).

: x(xPos), y(yPos)

This is an initializer list. Instead of assigning values inside the constructor body, it directly initializes the member variables x and y with the arguments xPos and yPos.

{}

The constructor body is empty because all the work (initialization) is already done in the initializer list.

A template class allows you to write a class once and use it with different data types without rewriting the code.

Microsoft Copilot

2025年11月25日星期二

Template function

A template function in C++ is a way to write a single function that works with multiple data types, avoiding code duplication.

A template allows you to define a function once and use it with different data types (like int, double, char).

It uses the keyword template followed by a type parameter inside angle brackets (<>).

In C++, the placeholder inside a template is the type parameter that represents a generic type.
It’s declared inside angle brackets (<>) after the keyword template.

A bit is the smallest unit of data in computing.

It can only have two possible values:

- 0 (off/false)

- 1 (on/true)

1 byte = 8 bits
This means a byte can represent 256 different values (from 0 to 255).

template <typename T>
int size_in_bit(T a) {
    return sizeof(a) * 8;
}

- template <typename T>
Declares a template with a placeholder type T. This allows the function to accept any data type (int, double, char, etc.).
- sizeof(a)
Returns the size of the variable a in bytes.
- * 8
Since 1 byte = 8 bits, multiplying by 8 converts the size into bits.
- Return type int
The function returns the number of bits as an integer.

int: 32 bits
double: 64 bits
char: 8 bits

Microsoft Copilot