api_hash.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. namespace Main {
  9. class Session;
  10. } // namespace Main
  11. namespace Api {
  12. [[nodiscard]] uint64 CountStickersHash(
  13. not_null<Main::Session*> session,
  14. bool checkOutdatedInfo = false);
  15. [[nodiscard]] uint64 CountMasksHash(
  16. not_null<Main::Session*> session,
  17. bool checkOutdatedInfo = false);
  18. [[nodiscard]] uint64 CountCustomEmojiHash(
  19. not_null<Main::Session*> session,
  20. bool checkOutdatedInfo = false);
  21. [[nodiscard]] uint64 CountRecentStickersHash(
  22. not_null<Main::Session*> session,
  23. bool attached = false);
  24. [[nodiscard]] uint64 CountFavedStickersHash(
  25. not_null<Main::Session*> session);
  26. [[nodiscard]] uint64 CountFeaturedStickersHash(
  27. not_null<Main::Session*> session);
  28. [[nodiscard]] uint64 CountFeaturedEmojiHash(
  29. not_null<Main::Session*> session);
  30. [[nodiscard]] uint64 CountSavedGifsHash(not_null<Main::Session*> session);
  31. [[nodiscard]] inline uint64 HashInit() {
  32. return 0;
  33. }
  34. inline void HashUpdate(uint64 &already, uint64 value) {
  35. already ^= (already >> 21);
  36. already ^= (already << 35);
  37. already ^= (already >> 4);
  38. already += value;
  39. }
  40. inline void HashUpdate(uint64 &already, int64 value) {
  41. HashUpdate(already, uint64(value));
  42. }
  43. inline void HashUpdate(uint64 &already, uint32 value) {
  44. HashUpdate(already, uint64(value));
  45. }
  46. inline void HashUpdate(uint64 &already, int32 value) {
  47. HashUpdate(already, int64(value));
  48. }
  49. [[nodiscard]] inline uint64 HashFinalize(uint64 already) {
  50. return already;
  51. }
  52. template <typename IntRange>
  53. [[nodiscard]] inline uint64 CountHash(IntRange &&range) {
  54. auto result = HashInit();
  55. for (const auto value : range) {
  56. HashUpdate(result, value);
  57. }
  58. return HashFinalize(result);
  59. }
  60. } // namespace Api