// // // This file is for Assignment 5, BU CAS CS 520, Fall, 2010 // // (* ****** ****** *) dataview slseg_v ( a:t@ype+, int, addr, addr ) = | {l:addr} slseg_v_nil (a, 0, l, l) of () | {l_fst,l_lst:addr | l_fst > null} {l_nxt:addr} {n:nat} slseg_v_cons (a, n+1, l_fst, l_lst) of ((a, ptr (l_nxt)) @ l_fst, slseg_v (a, n, l_nxt, l_lst)) // end of [slseg_v] (* ****** ****** *) viewdef cycbuf_v ( a:t@ype, m:int, n:int, l_fst: addr, l_lst: addr ) = (slseg_v (a, n, l_fst, l_lst), slseg_v (a?, m-n, l_lst, l_fst)) (* ****** ****** *) // // HX: 20 points // fun{a:t@ype} cycbuf_insert_back {m,n:int | 0 <= n; n < m} {l_fst,l_lst:addr} ( pf: cycbuf_v (a, m, n, l_fst, l_lst) | p_lst: ptr l_lst, x: a ) : [l_lst:addr] (cycbuf_v (a, m, n+1, l_fst, l_lst) | ptr l_lst) (* ****** ****** *) // // HX: 20 points // fun{a:t@ype} cycbuf_remove_frnt {m,n:int | 0 < n; n <= m} {l_fst,l_lst:addr} ( pf: cycbuf_v (a, m, n, l_fst, l_lst) | p_fst: ptr l_fst, x: &a? >> a ) : [l_fst:addr] (cycbuf_v (a, m, n-1, l_fst, l_lst) | ptr l_fst) (* ****** ****** *) (* end of [cycbuf.sats] *)