n_associated_ulong_srv.sru 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. $PBExportHeader$n_associated_ulong_srv.sru
  2. forward
  3. global type n_associated_ulong_srv from nonvisualobject
  4. end type
  5. end forward
  6. global type n_associated_ulong_srv from nonvisualobject
  7. end type
  8. global n_associated_ulong_srv n_associated_ulong_srv
  9. type variables
  10. private ulong il_keys[]
  11. private ulong il_key_count
  12. end variables
  13. forward prototypes
  14. public function unsignedlong of_add_key (unsignedlong al_val)
  15. public function unsignedlong of_find_key (unsignedlong al_val)
  16. public function unsignedlong of_get_key_index (unsignedlong al_val)
  17. public function integer of_sort_keys ()
  18. public function unsignedlong of_get_keys_count ()
  19. public function unsignedlong of_get_key (unsignedlong al_index)
  20. protected function unsignedlong of_get_index_min_key (unsignedlong al_from_key)
  21. end prototypes
  22. public function unsignedlong of_add_key (unsignedlong al_val);ulong ll_index
  23. if isnull(al_val) then
  24. return 0
  25. end if
  26. il_key_count ++
  27. il_keys[il_key_count] = al_val
  28. return il_key_count
  29. end function
  30. public function unsignedlong of_find_key (unsignedlong al_val);return of_get_key_index(al_val)
  31. end function
  32. public function unsignedlong of_get_key_index (unsignedlong al_val);ulong ll_i
  33. for ll_i = 1 to il_key_count
  34. if il_keys[ll_i] = al_val then
  35. return ll_i
  36. end if
  37. next
  38. return 0
  39. end function
  40. public function integer of_sort_keys ();integer li_ret = 1
  41. ulong ll_i
  42. ulong ll_cnt
  43. ulong ll_new_keys[]
  44. ulong ll_start_key
  45. ll_cnt = il_key_count
  46. do while true
  47. ll_i = of_get_index_min_key(ll_start_key)
  48. if ll_i > 0 then
  49. ll_cnt ++
  50. ll_new_keys[ll_cnt] = il_keys[ll_i]
  51. ll_start_key = il_keys[ll_i] + 1
  52. else
  53. exit
  54. end if
  55. loop
  56. il_keys = ll_new_keys
  57. il_key_count = upperbound(il_keys)
  58. return li_ret
  59. end function
  60. public function unsignedlong of_get_keys_count ();return il_key_count
  61. end function
  62. public function unsignedlong of_get_key (unsignedlong al_index);return il_keys[al_index]
  63. end function
  64. protected function unsignedlong of_get_index_min_key (unsignedlong al_from_key);ulong ll_ret
  65. ulong ll_i
  66. ulong ll_min_key = 4294967295
  67. for ll_i = 1 to il_key_count
  68. if il_keys[ll_i] >= al_from_key and il_keys[ll_i] <= ll_min_key then
  69. ll_ret = ll_i
  70. ll_min_key = il_keys[ll_i]
  71. end if
  72. next
  73. return ll_ret
  74. end function
  75. on n_associated_ulong_srv.create
  76. call super::create
  77. TriggerEvent( this, "constructor" )
  78. end on
  79. on n_associated_ulong_srv.destroy
  80. TriggerEvent( this, "destructor" )
  81. call super::destroy
  82. end on