Struct jbcrs_basic::Pool
[−]
[src]
pub struct Pool { /* fields omitted */ }
The constant pool found in every java class file.
It is used to have fast lookup for entries and small files.
Removing or modifying items is not allowed
to respect already 'used' indices
or to prevent rehashing of the underlying HashMap
.
A Vec
and a HashMap
is used internally to have fast lookups by index and value.
To connect both, Rc
s are used.
As a result, we will have a little overhead, but this should be negligible.
Methods
impl Pool
[src]
pub fn new() -> Self
[src]
pub fn with_capacity(cap: u16) -> Self
[src]
pub fn len(&self) -> u16
[src]
Returns the encoded length of the pool.
pub fn is_empty(&self) -> bool
[src]
Returns true if the pool is empty, false otherwise.
pub fn get(&self, index: u16) -> Result<&Item, Error>
[src]
Returns the item at a specified index. If the index is 0 or greater than the size of the pool, an error is returned.
pub fn get_utf8(&self, index: u16) -> Result<String, Error>
[src]
Returns a cloned String at a specified index.
pub fn get_class_name_opt(&self, index: u16) -> Result<Option<String>, Error>
[src]
Returns a class name at a specified index, but if the utf index is 0, None is returned.
pub fn get_class_name(&self, index: u16) -> Result<String, Error>
[src]
Returns a class name at a specified index.
pub fn push(&mut self, item: Item) -> Result<u16, Error>
[src]
Pushes an item on the pool.
pub fn push_duplicate(&mut self, item: Item) -> Result<u16, Error>
[src]
Pushes an item, which might be a duplicate. This removes the possibility of reading a class, which has multiple constant pool entries, which are the same and then accessing the wrong entry.
pub fn push_utf8(&mut self, content: String) -> Result<u16, Error>
[src]
Pushes a new UTF-8 item on the pool and returns an index to it.
pub fn push_class(&mut self, name: String) -> Result<u16, Error>
[src]
Pushes a new class item on the pool and returns an index to it.