14-445 from CMU
modified 20/04/2024 22:54Intro
Author of learnaifromscratch swears that this course teaches you everything you need to know to get a job in OLAP. I’ll do it to learn about sql and how databases work internally. I don’t know modern c++ (did a course in c++ that was more like in college but that’s about it), so I’ll pick that up too as I go.
Lecture 1
C++ Primer
Project requires us to implement a copy-on-write trie (operations return new tries, instead of modifying by reference) by completing the implementation. This is really a test for your c++ abilities. I don’t have any so I’ll be picking everything up and writing about what I learn here as I go through it.
std::string_view
- immutable read-only view(reference) to a string; use this when you don’t need to modify the string, but only to access it
trailing return types (fun -> type
)
- this allows infering types using
auto
, for example, in:
template <class T>
auto Trie::Get(std::string_view key) const -> const T *
{
}
- chatgpt says that this is only a matter of style, so it’s equivalent to
template <class T>
const T* Trie::Get(std::string_view key) const
{
}
i guess it’s more readable? not sure
std::dynamic_cast
explicit constructors
- using
explicit
in the constructor means that it won’t be usable for implicit type converstion; so you’ll only be able to initialize the object using the constructor, instead of also allowing to initialize it with assignment
virtual functions
- same concept as in OOP, allows a function to be overriden but this happens at runtime instead of compile time
why we can’t use the copy constructor
- not really sure?
pseudocode
-
Trie.Put(key: str, value: any)
for i in len(key): char = key[i] if not char in children: create children node with char as key val = str(value[i]) children[char] = val -
Trie.Get(key)
val = "" for i in len(key): char = key[i] val += children[char]return val