Does the integer metadata for a field count towards its allocated length?
Integer metadata values like field lengths and offsets are completely separate from the actual data. They don’t use up the bytes reserved for the field itself, but they do contribute to the length of the record.
For example, in lecture we looked at the way that the record
('1234567', 'comp sci', 200)
would be represented using
variable-length records with a header of offsets. In that example,
we used 2-byte offsets but 4-byte integer values, so the length
of the record ended up being 27 bytes:
When do we need to use a #
delimiter in a fixed-length record?
We use a #
as a delimiter at the end of a string value in a
fixed-length record if:
the string is in a variable-length field (e.g., a VARCHAR) and
the string is shorter than the maximum length of the variable-length field.
We don’t need those delimiter characters in any other circumstance.
When we do include a # character, it uses up 1 byte of the field’s allocated number of bytes.
For example, let’s say that we have a VARCHAR(10)
field as part
of a fixed-length record.
If you needed to store the string 'abc'
in that field, you would
use the string 'abc#------'
(abc
, followed by #
, followed by
6 hyphens), and the overall length of that field would be 10.
If you needed to store the string '0123456789'
in that field,
you would use the string '0123456789'
with no # and no hyphens,
since the value itself already uses up all 10 of the available
bytes.
In 2.3, when showing the before-and-after pictures for each increase in the number of buckets, should we include the key that causes the increase?
Yes. The problem states that a split should occur whenever the total number of items is greater than (3*number of buckets). This means that the split occurs after we go over the threshold, not before.
In the “before” table, you should include the key of the item that takes you over the threshold, and then the “after” table will also include that key.
For example, in the lecture notes, when we used the slightly different rule that a split occurs when the total number of items is greater than (2*number of buckets), you’ll see for example that we have a “before” picture with 3 buckets and 7 items, and then an “after” picture with 4 buckets and the same 7 items.
For my computeOffsets()
method, I’m trying to use the
length()
method from Java’s String
class to determine the
length of one of the elements of the fieldVals
array that I have
determined is a string. However, I get the following error message:
the method length is undefined for the type Object
How can I fix this?
Because the field values are stored in an array of type Object
,
you will need to use a type cast in order to treat them as objects
of their actual types. For example, to treat fieldVals[i]
as a
String
, you would need to do something like (String)fieldVals[i]
.
In order to call the length()
method on an element that you know
is a String
, you could use do something like
((String)fieldVals[i]).length()
Last updated on October 2, 2025.