-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes
77 lines (46 loc) · 3.51 KB
/
notes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
go:
make tests runs tests, and shows a bit of an avl tree
allocate(-2) is a very bad idea, especially during initialization. I have never seen such a mess before.
This is a copy assignment:
vector<std::string> v2;
v2 = v;
this is a copy constructor
vector<std::string> v2 = v;
They are not the same!
There is a difference between a vector and a copy, because the capacities are not the same. For the copy, the capacity is the same as the size;
With iterator traits you can see the internally use types of an intance. Usually your types are public and you can use your class to access them, but that's different from using an instance to access them. For instances you need iterator traits.
For pointers you have to handle iterator traits separately, and you can check if something is a pointer with a template specialisation.
https://www.programiz.com/dsa/avl-tree
My avltree is general, it takes <T>, but that doesn't work. Because sometimes it needs to find a key. That doesn't make sense if it doesn't know it has pairs? Or I could make a function that only works for pairs. Or I could passin the compare?
I still need to be better at this:
https://stackoverflow.com/questions/8788863/can-const-member-function-return-a-non-const-pointer-to-a-data-member
again encountered the problem where I call a function with a map, the function copies the map, the map copy constructor is not yet implemented, so it doesn't deep copy, the destructor does work, so the map gets removed, and then then I get use after free.
why is this ok?
-------node* find(const value_type& val) const
why doesn't the node* have to point to something const
because you can't actually change the members of the tree, because that only has a root pointer, and the value of that pointer will not be changed
and then the outside world will not notice a problem because te map itself converts it to a const_iterator
only use iterators at the map level, the rest just uses pointers
don't just resize when someone gives you an iterator in the thing
when using last + 1 as the end pointer, you can only recognize the end when you're not at the end, because you need something to dereference. So one way to fix that is to make end and actual node.
separate cpp:
-with templates
--error: out-of-line constructor for 'ra_iterator' cannot have template arguments
-without templates
--'ra_iterator' is not a class, namespace, or enumeration
to optimize!
--make test
--run instruments on some executable
--make slow thing faster
//https://www.cplusplus.com/reference/iterator/iterator/
//This base class only provides some member types, which in fact are not required to be present in any iterator type (iterator types have no specific member requirements), but they might be useful, since they define the members needed for the default iterator_traits class template to generate the appropriate instantiation automatically (and such instantiation is required to be valid for all iterator types).
https://stackoverflow.com/questions/14187006/is-calling-destructor-manually-always-a-sign-of-bad-design
pretty important:
You have to take the structure of each standard container as reference. If a part of the Orthodox Canonical form is missing in it, do not implement it.
cppreference does mention member object c:
https://en.cppreference.com/w/cpp/container/stack
but cplusplus doesn't:
https://cplusplus.com/reference/stack/stack/
optimizations:
check all nodes for rebalancing? or only parts where there has been an insertion or deletion?
use more state in map to make calculations quicker