Biblioteca de clases genéricas - errores, descripción, preguntas, características de uso y sugerencias - página 22

 
Alexey Navoykov:

Aparentemente no te refieres a la herencia, sino a una envoltura de una clase sobre una estructura?

de la derecha.
 
//+------------------------------------------------------------------+
//| Determines whether a set contains the specified element.         |
//+------------------------------------------------------------------+
template<typename T>
bool CHashSet::Contains(T item)
  {
//--- check buckets
   if(ArraySize(m_buckets)!=0)
     {
      //--- get hash code for item      
      int hash_code=m_comparer.HashCode(item)&0x7FFFFFFF;
      //--- search item in the slots       
      for(int i=m_buckets[hash_code%ArraySize(m_buckets)]-1; i>=0; i=m_slots[i].next)
         if(m_slots[i].hash_code==hash_code && m_comparer.Equals(m_slots[i].value,item))
            return(true);
     }
   return(false);
  }

¿Por qué se corta el trozo de señal?

 
fxsaber:

¿Por qué se corta la parte del cartel?

el hash debe ser positivo porque actúa como índice en el array

 
TheXpert:

el hash debe ser positivo porque actúa como índice en el array

¿unos?

 
fxsaber:

¿unos?

no tiene sentido

Документация по MQL5: Операции с массивами / ArraySize
Документация по MQL5: Операции с массивами / ArraySize
  • www.mql5.com
"Нулевое измерение = Размер массива / (Первое измерение * Второе измерение * Третье измерение)"
 
TheXpert:

no tiene sentido

La combinación de líneas resaltadas parece errónea

Foro sobre trading, sistemas de trading automatizados y pruebas de estrategias de trading

Biblioteca de clases genéricas - errores, descripción, problemas, casos de uso y sugerencias

fxsaber, 2018.06.11 20:04

//+------------------------------------------------------------------+
//| Determines whether a set contains the specified element.         |
//+------------------------------------------------------------------+
template<typename T>
bool CHashSet::Contains(T item)
  {
//--- check buckets
   if(ArraySize(m_buckets)!=0)
     {
      //--- get hash code for item      
      int hash_code=m_comparer.HashCode(item)&0x7FFFFFFF;
      //--- search item in the slots       
      for(int i=m_buckets[hash_code%ArraySize(m_buckets)]-1; i>=0; i=m_slots[i].next)
         if(m_slots[i].hash_code==hash_code && m_comparer.Equals(m_slots[i].value,item))
            return(true);
     }
   return(false);
  }

¿Cómo se compara un hachís recortado con uno sin cortar?

 
fxsaber:

¿Cómo se compara un hachís recortado con uno sin cortar?

Creo que todas están truncadas, aunque debo decir de entrada que sólo miré el código brevemente y hace mucho tiempo, así que podría estar equivocado.

Mira el código para añadir el artículo.

 
TheXpert:

Creo que están todos recortados, aunque debo decir de entrada que sólo he ojeado el código hace mucho tiempo, así que podría estar equivocado.

Mira el código para añadir un elemento.

//+------------------------------------------------------------------+
//| Insert the value with the specified key from the map.            |
//+------------------------------------------------------------------+
template<typename TKey,typename TValue>
bool CHashMap::Insert(TKey key,TValue value,const bool add)
  {
   if(m_capacity==0)
      Initialize(0);
//--- get hash code from key
   int hash_code=m_comparer.HashCode(key)&0x7FFFFFFF;
   int target_bucket=hash_code%m_capacity;
//--- collisions count in one bucket with different hashes
   int collision_count=0;
//--- search pair with specified key
   for(int i=m_buckets[target_bucket]; i>=0; i=m_entries[i].next)
     {
      //--- hash compare      
      if(m_entries[i].hash_code!=hash_code)
        {
         collision_count++;
         continue;
        }
      //--- value compare     
      if(m_comparer.Equals(m_entries[i].key,key))
        {
         //--- adding duplicate
         if(add)
            return(false);
         m_entries[i].value=value;
         return(true);
        }
     }
//--- check collision
   if(collision_count>=m_collision_threshold)
     {
      int new_size=CPrimeGenerator::ExpandPrime(m_count);
      Resize(new_size);
     }
//--- calculate index
   int index;
   if(m_free_count>0)
     {
      index=m_free_list;
      m_free_list=m_entries[index].next;
      m_free_count--;
     }
   else
     {
      if(m_count==ArraySize(m_entries))
        {
         int new_size=CPrimeGenerator::ExpandPrime(m_count);
         Resize(new_size);
         target_bucket=hash_code%new_size;
        }
      index=m_count;
      m_count++;
     }
//--- set pair
   m_entries[index].hash_code=hash_code;
   m_entries[index].next=m_buckets[target_bucket];
   m_entries[index].key=key;
   m_entries[index].value=value;
   m_buckets[target_bucket]=index;
   return(true);
  }

Sí, gracias, sólo que no hay ninguno que no esté recortado en código. Es extraño que no hayan hecho el recorte en el propio método HashCode. Al parecer, el cálculo era a prueba de tontos (hashtags personalizados torcidos).

 

Lo siento si esto ya ha ocurrido. No lo encontré en la documentación.

¿Hay algún bucle en Set-ups? ¿Itinerador?

 
Viktor Lubimov:

Lo siento si esto ya ha ocurrido. No lo encontré en la documentación.

¿Hay algún bucle en los montajes?

Por desgracia, no.
Pero puedes ponerlo en práctica tú mismo.
Por ejemplo, vea el ejemplo del artículoMQL5 RECEIPTS - REALICE UNA BASE DE DATOS MASIVA O MUNDIAL ASOCIADA PARA UN RÁPIDO ACCESO A LOS DATOS

void ReverseEnumerateAll(CList& list)
{
   CObject* node = list.GetLastNode();
   for(int i = list.Total()-1; node != NULL; i--, node = node.Prev())
      printf("Element at " + (string)i); 
}
Как работает этот код? На самом деле все просто. В функции EnumerateAll() в самом начале мы получаем ссылку на первый узел. Затем в цикле for мы печатаем порядковый узел этого узла 
и переходим к следующему узлу командой node = node.Next(), не забывая при этом проитерировать текущий индекс элемента на единицу (i++). Перебор продолжается до тех пор, пока текущий 
узел node не станет равен NULL, за это ответствен код во втором блоке for: node != NULL.

Аналогично работает реверсивная версия этой функции ReverseEnumerateAll() с той лишь разницей, что она вначале получает последний элемент списка CObject* node = list.GetLastNode(). 
В цикле for она получает не следующий, а предыдущий элемент списка node = node.Prev().