KISS πŸ‡ΊπŸ‡¦

Stop the war!

Stop the war in Ukraine! Fuck putin!

More information is at: https://war.ukraine.ua/.

There is a fund to support the Ukrainian Army: https://savelife.in.ua/en/donate/, and there is a special bank account that accepts funds in multiple currencies: https://bank.gov.ua/en/about/support-the-armed-forces. I donated to them. Please donate if you can!

Killer putin

Killer putin. Source: politico.eu.

Arrested putin

"It hasn't happened yet, but it will happen sooner or later. Beautiful photo, isn't it?" Source: twitter.

HashMapT in Bada

| comments

Hash map (a.k.a. dictionary) is a useful and convenient data structure. Bada SDK provides HashMap and HashMapT classes implementing it. I normally used the templated version of it, HashMapT. However, I came across the fact that it supported neither base class String nor DateTime out-of-box.

The following classes, children of IHashCodeProviderT<> and IComparerT<>, solve this misunderstanding:

HashMapTExtensions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * HashMapTExtensions.h
 */

#ifndef HASHMAPTEXTENSIONS_H_
#define HASHMAPTEXTENSIONS_H_

#include <FBase.h>

// The following *KeyHashCodeProvider classes are required to use
// String and DateTime as a key for HashMapT
class StringKeyHashCodeProvider: public Osp::Base::Collection::IHashCodeProviderT<
      Osp::Base::String>
{
public:
  virtual int GetHashCode(const Osp::Base::String &obj) const;
};

class DateTimeKeyHashCodeProvider: public Osp::Base::Collection::IHashCodeProviderT<
      Osp::Base::DateTime>
{
public:
  virtual int GetHashCode(const Osp::Base::DateTime &obj) const;
};


// The following *KeyComparer classes are required to use
// String and DateTime as a key for HashMapT
class StringKeyComparer: public Osp::Base::Collection::IComparerT<
      Osp::Base::String>
{
public:
  virtual result Compare(const Osp::Base::String &obj1,
          const Osp::Base::String &obj2, int &cmp) const;
};

class DateTimeKeyComparer: public Osp::Base::Collection::IComparerT<
      Osp::Base::DateTime>
{
public:
  virtual result Compare(const Osp::Base::DateTime &obj1,
          const Osp::Base::DateTime &obj2, int &cmp) const;
};

#endif /* HASHMAPTEXTENSIONS_H_ */
HashMapTExtensions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * HashMapTExtensions.cpp
 */

#include "HashMapTExtensions.h"

using namespace Osp::Base;

int StringKeyHashCodeProvider::GetHashCode(const String &obj) const
{
  return obj.GetHashCode();
}

int DateTimeKeyHashCodeProvider::GetHashCode(const DateTime &obj) const
{
  return obj.GetHashCode();
}


result StringKeyComparer::Compare(const String &obj1, const String &obj2,
      int &cmp) const
{
  cmp = obj1.CompareTo(obj2);
  return E_SUCCESS;
}

result DateTimeKeyComparer::Compare(const DateTime &obj1, const DateTime &obj2,
      int &cmp) const
{
  cmp = obj1.CompareTo(obj2);
  return E_SUCCESS;
}

Then you use the classes when Constructing a HashMapT object.

Comments