>> We've got some of those
[inaudible] sets we want
to talk about, maps or tables.
On -- well, what is a table, really?
Well, we model [inaudible] dictionary,
mapping, map -- map that I'm splitting,
the terminology used in the [inaudible].
Table is actually the most common
generic use, the term used [inaudible].
There's also this associated
array which is really a table.
We'll talk about that and what
an associative array is a table
with a bracket operator but the
bracket operator doesn't take integers.
It doesn't take the integers or
inside the brackets, it's an argument.
It takes key values or P is in some
[inaudible] such as [inaudible].
And it has some special
inserts semantics.
Now, tables are typically going
to have unimodal semantics
with duplicate elements not allowed.
So our Table API's going
to look like this.
It's going to have "Insert," "Remove."
It's going to have an
"includes," "Empty," and "Size",
and "Clear" just like set did.
But it's going to have one more thing
called "Retrieve" which only makes sense
when you have a table interface and now,
let's look at what we're
talking about here.
In a table, we have instead
of a single value
in there; we have a pair of values.
There's the first thing is a "Key"
coming from something called "Key Type"
and the second thing is something
called "Data" coming from a data file.
That should [inaudible] that
probably there should be an ampersand
when we're [inaudible] references.
"Removal" will be by "Key"
where it makes the table empty.
"Include" you get a "Key" that returns
an iterator pointing to something
and we'll talk about what in a minute.
And they give you a support
system, live operators [inaudible].
So, the one thing that's kind of new
here is this "Retrieve" operation notice
that with a set, [inaudible] two things
which define the subset
[phonetic] iterator
and returning the iterator [inaudible].
With a table, the quantity is dividing
what we're restoring into two things,
a "Key" thing and a "Data" thing.
You can pass in a key by cross reference
and you can pass in a
"Data" by reference.
That is not [inaudible]
since [inaudible].
So, with the way the "Key" works
is, it looks up the key in the table
and then puts the data stored with that
key into this variable a kind of a way
of returning it to "Retrieve" operation.
So, that data that I've got
glued there is populated
with the status stored with the key.
That's presuming the key was found.
If the key is not found, that data is
not defined and we'll take a "False".
Let's look at an example here.
We'll talk about Semantics first.
Table Semantics and Unimodal --
so, you can't have a key appearing
more than once in the table.
So, that means your "Insert", you've
got to have this dual personality.
If the key is in the table, and
insert KD overwrites the stored data
with [inaudible].
The size of the table remains the same.
If the key is not in the table, then the
entire pair is inserted into the table,
"Key" and "Data" and the size of
the table is increased by one.
And here's your "Retrieve" operation
again, so if K is in the table,
what this does is set "D" adds reference
to the stored data and return "True",
otherwise it becomes "False".
If you move a key, it moves that pair
and decrease the size
of the table by one.
The key can only be in there once,
right, so it returns either one a zero
and interpret that to be "False".
If "K" is not in the table, then
of course, nothing will move.
The table is unchanged; the size is
unchanged then "False" will be changed.
The iterator includes -- this is kind
of a subtle point here but it's going
to return a pointer, or an iterator that
points to the pair, the key data pair
in the table, not just to the
data and not just to the key.
And it will return the end iterator if
the "K" is not there, a sign obviously
that he's not yet returned his number.
Or there's another way,
the number of "Key"
"Data" players, so on and so forth.
So, let's look more carefully as this
API and see if our swap's been fixed.
You got your insert,
that's the key in the data.
That's supposed to have an ampersand
when it's applied to put an ampersand in
and I'd probably put an ampersand
in and forgot to put that in.
So, it's not [inaudible].
"Remove" if that's a key and removes
all copies of that key in the framework.
Of course, there can be only one
property so that light will be a zero.
But we go ahead and call it
a size and I'm just going
to tell you just for consistency.
"Clear" makes "Data Retrieve", populates
that with the available assorted
activity and we got "Include",
then we've got "LowerBound" and
"UpperBound" [inaudible] table.
And all these operations are just
like the ones for "Set", instead,
they focus on the key itself.
So, on or Ordered Table Semantics
are the table that's the same
as unordered case.
But "Traversal" will encounter keys
in sorted order just like for a set --
Traversal of a set, an ordered set when
"Encounter" key is in sorted order.
"LowerBound" will point to the
first pair in the table such that
"K1" was figuring where to put "K",
"K" being the argument passed in
and "Upper Bound" [inaudible] with "K" ,
the first pair on the table is such that
"K1, D1" in the table such
that K1 is [inaudible] just
like a [inaudible] to say [inaudible].
Just concentrating on looking at key
decisions and ignoring the [inaudible].
Okay, let's talk about this
"Associative Array" type [inaudible].
First of all, there's -- when
you have an associative array,
it's traditional means of
operations could get --
and I'm going to probably
erase -- so, put "K,D", put --
you know, it's a unimodal insert
of that pair "K,D" and the type.
So, "Get" -- well, "Get"
going to state a key
as its argument and return
a [inaudible].
So, it's going to return the
[inaudible] associated with the key.
Now, the problem is how do you
know that key is in the inventory?
Well, you don't.
So, "Get" has to insert K into
the [inaudible] that's not there,
although it couldn't return anything.
So, this is a very, very difficult
thing to get your head around.
"Get" plays an insert [inaudible] in
section one and "Erase" will ensure
that "K" is not in the table.
Now, this is why people like Associative
Arrays is so called syntactic sugar.
So, it's a bracket operator.
So, this is the thing, "Operator
Bracket" but it takes key type
as its argument, not an integer.
And what it is you'll
probably get on that key,
"Get Return Data Type" [inaudible].
And so, that's what "Get" returns.
So, it's -- the "Bracket Operator"
is kind of like a call of a "Get,"
but again, it retrieves --
so, let's just think about it.
So, what if the "K" is in the table
and of course, "Get" will find it
and return the data associated with it.
Now, we're talking about
a "Bracket Operator".
What if "K" is not in the table?
Well "Get" will put it in the table
associated with a data answer --
that data answer recreated by
the default contract [inaudible]
and will return that with [inaudible],
notice my reference so you'll be able
to put stuff into that "Data"
slot when it gets your turn.
So, that's -- that's a little bit
of [inaudible] just checking
on [inaudible].
[ Inaudible Speaker ]
So, [inaudible] --
Okay, I thought I had
[inaudible] on there.
I guess I don't.
So, anyway -- let's go on here.
So, how can -- how can place
[inaudible] in all this
or we can get this notion of "Entry".
It's just really a special kind of
player or we're trying to place "Entry"
and it's basically going to
be a structure if you want it.
So, struct meaning almost
all the elements
that you find are default-phobic.
So, we have a "Key" underscore
and the data underscore
and an "Insert" and have "Construct".
So, we're going to find what we
mean by a quality or two entries.
They're equal if they have the
"Keys", maybe more of the data.
You can find a [inaudible].
That's saying you have to keep one key
for [inaudible] left from K through 2.
He would know where the
data is, the sideline.
Okay, this is tricky but if the
two entities have equal keys,
then you copy the data over.
Otherwise, there's an error.
But you're allowed [inaudible]
only between "Entry" of equal keys
and when we have "Entry" keys you
only assign the data, not the key.
There's no need to assign the key,
because it's [inaudible],
it's the thinking of it.
So, we can make a set of "Entries"
and what they call the "Table".
So, the "Table", we can make quite a
table by [inaudible] a set of "Entry".
We call it "One-to-One Table".
So, you insert "K, D" would be
[inaudible] on making an entry
and "Entry" would take the unit and
inserting that into the "Entry Set".
[Inaudible].
The tree would look like this.
Make yourself an "Entry" object with
a default [inaudible], called "Set,
Iterator, Include" on that entry.
In fact, turn the "Iterator"
[inaudible] it didn't find
that in the [inaudible],
so it returned "False".
Otherwise, you'd let "D, D"
iterator be preference, dot data.
Now here, put the stored
data in that [inaudible].
So, that's how you would implement
a table just using any one
of those sets we've already got or
that we might make in the future.
Let's make a set of players
that becomes a table.
So, in some sets, there's
not a whole lot
of difference between a set and a table.
It's just so [inaudible] difference.
Tables can be more convenient than
sets only because we know that the keys
and this data, and a key in
a set is what is important.
The structure of the set [inaudible],
the data is what it's playing for,
for the structure [inaudible].
Very often, you got a set of objects
and those objects will have one field
called [inaudible] and so that again,
behaves just like a [inaudible].
Now, you can implement
an associative array
with a set comparing to its [inaudible].
Let's talk about that.
So, you put an operation.
We've got a "K" and a "D".
And we put -- we created an entry
and we just insert that entry
into the set, the undergoing set.
Now, if the set's unimodal,
that would be a unimodal insert
and what will that mean?
That means that [inaudible]
based on the sideline or go back
to the [inaudible] for "Entry".
It ignored the first check
to be sure [inaudible]
that [inaudible] data portion.
And so, we've built in a safeguard here
where we can't put it in the wrong place
if you like and that's the end of it.
So, "Get" would look like
this, "A data entry with a sort
of default data [inaudible]."
Search for the location
that should be in the table.
If you're at an end, that means you
didn't find it, so you insert it
and you let "Table" [inaudible]
includes "Search For" again and find it.
Otherwise, you just "Return"
[inaudible] not otherwise.
So, if it wasn't in there,
you put it in.
If it was in there, you
do nothing, right?
And in either case, it's there now so
you return the data boxes [inaudible].
An array should be implemented
[inaudible].
Here's my "Private" set down here.
So, what I want to just
point out here is that now,
because we have really got
two ways to implement set,
one of which is pretty good.
We have two ways to empty
that table and two ways
to implement an associative array.
It's based on a set or an
increase for a set of tires.
So, let's talk now about
using [inaudible].
This is what I was looking for
before -- I'd forgotten where it was.
So, let's say we're going
to make an associative array
of String comma Int [inaudible]
way and let's say that is specific,
"Key", plus "Specific String".
And that's some data.
You got a string, see you got to open a
file, you can read the key and some data
out of that file This code -- this
is code that actually works --
so then you can do A. A double "A" is
a name of our -- say, "It's Double A".
You can do, "Double A bracket
or Key equals some data.
Now notice Dr. [inaudible],
that inserts AP some way.
That is essentially a foot operation,
accomplishing the bracket
and we close the file.
So now, when we loaded all
the key data affairs that were
in that cloud and so [inaudible].
Many a query might be and our key,
somebody enters a key and [inaudible],
then data from that key, double
A bracket key and [inaudible] --
well, that's the sort of [inaudible]
you're associated with the [inaudible]
so assuming the key is
actually in there.
So, this little -- this little bit
of code here [inaudible] if we put
and "Get" and "Behavior" [inaudible]
associative array practice.
[Inaudible] when you get a little bit
used to this, it's extremely handy
and there's some programming
scripting languages
that basically use associative
arrays and almost nothing else
for their data structures, particularly
languages that are designed to work
with string [inaudible] and so on.
Associative Array is a
big deal [inaudible].
So, anyway we now [inaudible]
associative arrays in C plus plus
and [inaudible] it is now, it's not
just a built-in type in the language,
but with our associative array,
we can build it on top of any set
into the [inaudible] and we've
got one pretty good one now
where the retrieval is efficient
and one that's built on [inaudible].
We're going to have some more.
We're going to have a set
built on binary circuitries,
we're going to have a set built
on self-balancing [inaudible],
and later on, we're going to show how
to do your own ordered
versions using hash [inaudible]
and all those can be boiled down to
an associative array [inaudible].
So, this [inaudible] analysis of
the runtimes for table, insert --
what we've [inaudible]
so far is our "Insert",
my "Remove" operations are
going to be still linear.
But we can for use [inaudible], we
can get our "Retrieve" operation
to be logarithmic [inaudible].