2015-11-07 23:54:47 +01:00
|
|
|
class Word < Object
|
2015-11-10 18:08:48 +01:00
|
|
|
|
|
|
|
int char_at(int index)
|
2015-11-11 19:36:07 +01:00
|
|
|
int word_index = index - 1
|
2015-11-12 19:03:57 +01:00
|
|
|
word_index = word_index >> 2
|
2015-11-11 19:36:07 +01:00
|
|
|
word_index = word_index + 3
|
|
|
|
int rest = index - 1
|
2015-11-13 19:46:27 +01:00
|
|
|
rest = rest.mod4()
|
2015-11-11 19:36:07 +01:00
|
|
|
int char = get_internal(word_index)
|
|
|
|
int shifted = 8 * rest
|
|
|
|
shifted = char >> shifted
|
|
|
|
int ret = shifted & 255
|
|
|
|
return ret
|
2015-11-08 16:11:03 +01:00
|
|
|
end
|
2015-11-10 18:08:48 +01:00
|
|
|
|
|
|
|
int set_length(int i)
|
|
|
|
set_internal( 2 , i)
|
|
|
|
return i
|
|
|
|
end
|
|
|
|
|
2015-11-11 19:36:07 +01:00
|
|
|
Word push_char(int char)
|
|
|
|
int index = self.char_length + 1
|
|
|
|
self.set_length(index)
|
|
|
|
|
|
|
|
int word_index = index - 1
|
2015-11-12 19:03:57 +01:00
|
|
|
word_index = word_index >> 2
|
2015-11-11 19:36:07 +01:00
|
|
|
word_index = word_index + 3
|
|
|
|
|
|
|
|
int rest = index - 1
|
2015-11-13 19:46:27 +01:00
|
|
|
rest = rest.mod4()
|
2015-11-11 19:36:07 +01:00
|
|
|
|
|
|
|
int shifted = rest * 8
|
|
|
|
shifted = char << shifted
|
|
|
|
|
|
|
|
int was = get_internal( word_index )
|
|
|
|
int mask = rest * 8
|
|
|
|
mask = 255 << mask
|
|
|
|
mask = 4294967295 - mask
|
|
|
|
|
|
|
|
int masked = was & mask
|
|
|
|
int put = masked + shifted
|
|
|
|
|
|
|
|
set_internal( word_index , put )
|
|
|
|
|
2015-11-08 16:11:03 +01:00
|
|
|
return self
|
|
|
|
end
|
2015-11-07 23:54:47 +01:00
|
|
|
end
|