James Giles wrote:
> This part of what you're talking about I've been working
> at as part of my preprocessed language. I tend to mimic the
> way virtual memory hardware works. The data (regardless
> of it's actual size) is allocated in chunks (usually some multiple
> of the size of a NODE).
I do the same---I call it a paging system, and use a preprocessor to
make macros which make for some data-abstraction and hide the layer of
page indirections. A snip of the involved TYPE definitions is below. It
is not all perfect though: Each node in my implementation stores which
page it is on, so it knows it is paged. Can this be avoided, and if so,
how do I then delete nodes from the pages if I am only passed a node?
TYPE, PUBLIC :: Node_Key_i_dp
TYPE (Entry_Key_i_dp) :: my_data
INTEGER (KIND=i_next) :: my_max_level = 1, my_page = 1
INTEGER (KIND=i_wp) :: my_next = 0
END TYPE
TYPE, PUBLIC :: NodePointer_Key_i_dp
TYPE (Node_Key_i_dp), POINTER :: my_node => NULL ()
END TYPE
TYPE, PUBLIC :: PageOfNodes_Key_i_dp
TYPE (Node_Key_i_dp), DIMENSION (:), ALLOCATABLE :: my_nodes
TYPE (NodePointer_Key_i_dp), DIMENSION (:), &
ALLOCATABLE :: my_pointers
INTEGER (KIND=i_wp) :: my_n_nodes = 0
TYPE (NodePointer_Key_i_dp) :: my_free_node
INTEGER (KIND=i_next) :: my_next = 0
END TYPE
TYPE, PUBLIC :: VirtualMemoryForNodes_Key_i_dp
TYPE (PageOfNodes_Key_i_dp), DIMENSION (:), ALLOCATABLE :: my_pages
REAL (KIND=r_sp) :: my_p = 0.25_r_sp, my_log_p = - 1.386294_r_sp
INTEGER (KIND=i_wp) :: my_page_size = - 1
INTEGER (KIND=i_next) :: my_n_lists = 0, my_max_lists = 1
INTEGER (KIND=i_next) :: my_max_pages = 10, my_n_pages = 0
INTEGER (KIND=i_next) :: my_free_page = 0
END TYPE
TYPE, PUBLIC :: SkipList_Key_i_dp
TYPE (Node_Key_i_dp), POINTER :: my_head => NULL (), &
my_tail => NULL ()
TYPE (NodePointer_Key_i_dp), DIMENSION (:), &
ALLOCATABLE :: my_search_finger
TYPE (VirtualMemoryForNodes_Key_i_dp) :: my_memory
INTEGER (KIND=i_next) :: my_n_levels = 0, my_max_levels = 0
INTEGER (KIND=i_wp) :: my_n_elements = 0, my_max_elements = 1000
LOGICAL (KIND=l_short) :: my_use_search_finger = .TRUE., &
my_keep_duplicates = .FALSE., my_trace_allocation = .TRUE.
END TYPE
> I don't know how you would do this directly in Fortran without
> exposing the extra level of indirection to view.
Can it be done in other languages? I want to separate the code (not
preprocessor, but true compiled language) for the data structure from
the allocator itself, and yet have a relocatable structure. I guess by
using inlined indexing operators in C++ one can do it, but I would love
to see an example whose syntax I can actually read and understand how
it does it. Maybe you can post a little example of your own?
Thanks,
Aleks
|