!> Vector ๆดๅๅ้ module seakeeping_collection_vector_int use seakeeping_kinds, only: rk => sk_real_kind implicit none private public :: vector_int !> Vector_int ๆดๅๅ้ type vector_int private integer, public :: len = 0 !! ๆๆๅ้้ฟๅบฆ integer, allocatable :: items(:) !! ๆดๅๆฐ็ป contains procedure :: init procedure :: push, pop procedure :: get, set procedure :: clear procedure, private :: extend end type vector_int contains !> ๅๅงๅๅ้ pure subroutine init(self) class(vector_int), intent(inout) :: self self%len = 0 if (.not. allocated(self%items)) allocate (self%items(256)) end subroutine init !> ๅ้ๆฉๅฎน pure subroutine extend(self) class(vector_int), intent(inout) :: self integer, allocatable :: tmp(:) allocate (tmp(size(self%items))) self%items = [self%items, tmp] end subroutine extend !> ๅ้ๅๅ ฅ pure subroutine push(self, item) class(vector_int), intent(inout) :: self integer, intent(in) :: item if (self%len == size(self%items)) call self%extend() self%len = self%len + 1 self%items(self%len) = item end subroutine push !> ๅ้ๅผนๅบ pure subroutine pop(self, item) class(vector_int), intent(inout) :: self integer, intent(out), optional :: item if (self%len == 0) return if (present(item)) item = self%items(self%len) self%len = self%len - 1 end subroutine pop !> ๅ้่ทๅ pure subroutine get(self, index, item) class(vector_int), intent(in) :: self integer, intent(in) :: index integer, intent(out) :: item if (index < 1 .or. index > self%len) return item = self%items(index) end subroutine get !> ๅ้่ฎพ็ฝฎ pure subroutine set(self, index, item) class(vector_int), intent(inout) :: self integer, intent(in) :: index integer, intent(in) :: item if (index < 1 .or. index > self%len) return self%items(index) = item end subroutine set !> ๅ้ๆธ ็ฉบ pure subroutine clear(self) class(vector_int), intent(inout) :: self deallocate (self%items) self%len = 0 end subroutine clear end module seakeeping_collection_vector_int