Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
1.6 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. hashimp.h
  4. Abstract :
  5. This file contains the inline functions required to implement
  6. the hash tables defined in hashmap.h
  7. --*/
  8. #ifndef _HASHIMP_H_
  9. #define _HASHIMP_H_
  10. inline
  11. IStringKey::IStringKey(
  12. LPBYTE pbKey,
  13. DWORD cbKey ) :
  14. m_lpbKey( pbKey ),
  15. m_cbKey( cbKey ) {
  16. }
  17. inline LPBYTE
  18. IStringKey::Serialize(
  19. LPBYTE pbPtr
  20. ) const {
  21. PDATA pData = (PDATA)pbPtr ;
  22. pData->cb = (WORD)m_cbKey ;
  23. CopyMemory( pData->Data, m_lpbKey, m_cbKey ) ;
  24. return pData->Data + m_cbKey ;
  25. }
  26. inline LPBYTE
  27. IStringKey::Restore(
  28. LPBYTE pbPtr,
  29. DWORD &cbOut
  30. ) {
  31. PDATA pData = (PDATA)pbPtr ;
  32. if( m_cbKey < pData->cb ) {
  33. cbOut = pData->cb ;
  34. SetLastError( ERROR_INSUFFICIENT_BUFFER ) ;
  35. return 0 ;
  36. }
  37. cbOut = m_cbKey = pData->cb ;
  38. CopyMemory( m_lpbKey, pData->Data, m_cbKey ) ;
  39. return pData->Data + m_cbKey ;
  40. }
  41. inline DWORD
  42. IStringKey::Size() const {
  43. return sizeof( SerializedString ) - sizeof( BYTE ) + m_cbKey ;
  44. }
  45. inline BOOL
  46. IStringKey::Verify(
  47. LPBYTE pbContainer,
  48. LPBYTE pbPtr,
  49. DWORD cb
  50. ) const {
  51. PDATA pData = (PDATA)pbPtr ;
  52. if( pData->cb > cb ) {
  53. return FALSE ;
  54. }
  55. return TRUE ;
  56. }
  57. inline DWORD
  58. IStringKey::Hash( ) const {
  59. return CHashMap::CRCHash( m_lpbKey, m_cbKey ) ;
  60. }
  61. inline BOOL
  62. IStringKey::CompareKeys(
  63. LPBYTE pbPtr
  64. ) const {
  65. PDATA pData = PDATA( pbPtr ) ;
  66. return pData->cb == m_cbKey && !memcmp( pData->Data, m_lpbKey, m_cbKey ) ;
  67. }
  68. inline LPBYTE
  69. IStringKey::EntryData(
  70. LPBYTE pbPtr,
  71. DWORD &cbOut
  72. ) const {
  73. PDATA pData = PDATA( pbPtr ) ;
  74. return pData->Data + pData->cb ;
  75. }
  76. #endif // _HASHIMP_H_