paging_util.go 691 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * EliasDB
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. */
  10. package paging
  11. /*
  12. CountPages counts the number of pages of a certain type of a given PagedStorageFile.
  13. */
  14. func CountPages(pager *PagedStorageFile, pagetype int16) (int, error) {
  15. var err error
  16. cursor := NewPageCursor(pager, pagetype, 0)
  17. page, _ := cursor.Next()
  18. counter := 0
  19. for page != 0 {
  20. counter++
  21. page, err = cursor.Next()
  22. if err != nil {
  23. return -1, err
  24. }
  25. }
  26. return counter, nil
  27. }