# Path: pyfive/core.py
# def _padded_size(size, padding_multipe=8):
#     """ Return the size of a field padded to be a multiple a give value. """
#     return int(ceil(size / padding_multipe) * padding_multipe)
# 
# Path: pyfive/core.py
# def _unpack_struct_from_file(structure, fh):
#     """ Unpack a structure into an OrderedDict from an open file. """
#     size = _structure_size(structure)
#     buf = fh.read(size)
#     return _unpack_struct_from(structure, buf)
# 
# Path: pyfive/core.py
# class Reference(object):
#     """
#     HDF5 Reference.
#     """
# 
#     def __init__(self, address_of_reference):
#         self.address_of_reference = address_of_reference
# 
#     def __bool__(self):
#         # False for null references (address of 0) True otherwise
#         return bool(self.address_of_reference)
# 
#     __nonzero__ = __bool__  # Python 2.x requires __nonzero__ for truth value


from collections import OrderedDict
from .core import _padded_size
from .core import _unpack_struct_from_file
from .core import Reference
import struct
import zlib
import numpy as np
    HDF5 version 1 B-Tree storing raw data chunk nodes (type 1).
    """

    def __init__(self, fh, offset, dims):
        """ initalize. """
        self.fh = fh
        self.dims = dims

        # read in the root node
        root_node = self._read_node(offset)
        self.root_node = root_node

        # read in all other nodes
        all_nodes = {}
        node_level = root_node['node_level']
        all_nodes[node_level] = [root_node]
        while node_level != 0:
            new_nodes = []
            for parent_node in all_nodes[node_level]:
                for addr in parent_node['addresses']:
                    new_nodes.append(self._read_node(addr))
            new_node_level = new_nodes[0]['node_level']
            all_nodes[new_node_level] = new_nodes
            node_level = new_node_level

        self.all_nodes = all_nodes

    def _read_node(self, offset):
        """ Return a single node in the b-tree located at a give offset. """
        self.fh.seek(offset)

# Path: pyfive/core.py
# def _padded_size(size, padding_multipe=8):
#     """ Return the size of a field padded to be a multiple a give value. """
#     return int(ceil(size / padding_multipe) * padding_multipe)
# 
# Path: pyfive/core.py
# def _unpack_struct_from_file(structure, fh):
#     """ Unpack a structure into an OrderedDict from an open file. """
#     size = _structure_size(structure)
#     buf = fh.read(size)
#     return _unpack_struct_from(structure, buf)
# 
# Path: pyfive/core.py
# class Reference(object):
#     """
#     HDF5 Reference.
#     """
# 
#     def __init__(self, address_of_reference):
#         self.address_of_reference = address_of_reference
# 
#     def __bool__(self):
#         # False for null references (address of 0) True otherwise
#         return bool(self.address_of_reference)
# 
#     __nonzero__ = __bool__  # Python 2.x requires __nonzero__ for truth value


# Path: pyfive/btree.py
from collections import OrderedDict
from .core import _padded_size
from .core import _unpack_struct_from_file
from .core import Reference
import struct
import zlib
import numpy as np

    HDF5 version 1 B-Tree storing raw data chunk nodes (type 1).
    """

    def __init__(self, fh, offset, dims):
        """ initalize. """
        self.fh = fh
        self.dims = dims

        # read in the root node
        root_node = self._read_node(offset)
        self.root_node = root_node

        # read in all other nodes
        all_nodes = {}
        node_level = root_node['node_level']
        all_nodes[node_level] = [root_node]
        while node_level != 0:
            new_nodes = []
            for parent_node in all_nodes[node_level]:
                for addr in parent_node['addresses']:
                    new_nodes.append(self._read_node(addr))
            new_node_level = new_nodes[0]['node_level']
            all_nodes[new_node_level] = new_nodes
            node_level = new_node_level

        self.all_nodes = all_nodes

    def _read_node(self, offset):
        """ Return a single node in the b-tree located at a give offset. """
        self.fh.seek(offset)

        node = _unpack_struct_from_file(B_LINK_NODE_V1, self.fh)