1. Список говнокодов пользователя j123123

    Всего: 332

  2. Си / Говнокод #29001

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    // https://github.com/micropython/micropython/blob/1b89c503db690967d50699abe0bfa942f6f6b15e/ports/qemu/mcu/rv32/interrupts.c#L131
    
    const char *lookup_cause(uint32_t mcause) {
        if (mcause & 0x80000000) {
            switch (mcause & 0x7FFFFFFF) {
                case 1:
                    return exception_causes[1];
                case 3:
                    return exception_causes[2];
                case 5:
                    return exception_causes[3];
                case 7:
                    return exception_causes[4];
                case 9:
                    return exception_causes[5];
                case 11:
                    return exception_causes[6];
                default:
                    return (mcause >= 16) ?
                           exception_causes[7] :
                           exception_causes[0];
            }
        }
    
        switch (mcause) {
            case 0:
                return exception_causes[8];
            case 1:
                return exception_causes[9];
            case 2:
                return exception_causes[10];
            case 3:
                return exception_causes[11];
            case 4:
                return exception_causes[12];
            case 5:
                return exception_causes[13];
            case 6:
                return exception_causes[14];
            case 7:
                return exception_causes[15];
            case 8:
                return exception_causes[16];
            case 9:
                return exception_causes[17];
            case 11:
                return exception_causes[18];
            case 12:
                return exception_causes[19];
            case 13:
                return exception_causes[20];
            case 15:
                return exception_causes[21];
            default: {
                if ((mcause >= 24 && mcause <= 31) ||
                    (mcause >= 48 && mcause <= 63)) {
                    return exception_causes[22];
                }
    
                return exception_causes[0];
            }
        }
    }

    Микропитухон

    j123123, 18 Октября 2024

    Комментарии (4)
  3. Куча / Говнокод #28930

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    import std.stdio;
    import std.conv;
    
    bool[128][128] a;
    
    int pow2(int x) { return x * x; }
    
    string GenPw(string x, string y, string r)
    {
        return "pow2("~r~") > pow2("~x~") + pow2("~y~")";
    }
    
    
    string GenPat(int x_sz, int y_sz, string x_str, string y_str, string r_str, string pat)
    {
      string GenCond = "(";
      foreach (y; 0 .. y_sz)
        foreach (x; 0 .. x_sz)
        {
          if(pat[(y) * x_sz + x] == '1')
          {
            if(GenCond == "(") GenCond ~= "\n     ";
            else GenCond ~= "  && ";
            GenCond ~= "("~GenPw(to!string(x)~"+("~x_str~")",to!string(y)~"+("~y_str~")",r_str)~")\n";
          }
        }
      return GenCond ~ ")";
    }
    
    bool checkCoordNeihb(int x, int y, int r)
    {
        if (pow2(r) > pow2(x) + pow2(y))
        {
            /// Паттерн-матчинг, если
            /// 111
            /// 101
            /// 111
            /// то пиксель 0
            if (
                mixin
                (
                  GenPat
                  (
                    3,3,
                    "x-1",
                    "y-1",
                    "r",
                    "111"~
                    "101"~
                    "111"))
            )
                return false;
            return true;
        }
        return false;
    }
    
    void drawCircle(ref bool[128][128] a, int x, int y, int r)
    {
        foreach (iy; y - r .. y + r)
        {
            foreach (ix; x - r .. x + r)
            {
                if (checkCoordNeihb(ix - x, iy - y, r))
                    a[ix][iy] = true;
            }
        }
    }
    
    void main()
    {
        drawCircle(a, 24, 24, 15);
    
        writeln("\n\n");
        foreach (ix; 0 .. 128)
        {
            foreach (iy; 0 .. 128)
            {
                write(a[ix][iy] ? '1' : '0');
            }
            writeln();
        }
    }

    Переписал на "D" https://govnokod.ru/27990#comment1183758

    j123123, 20 Марта 2024

    Комментарии (20)
  4. Куча / Говнокод #28799

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    // https://github.com/torvalds/linux/blob/b6dad5178ceaf23f369c3711062ce1f2afc33644/rust/alloc/alloc.rs#L376
    pub const fn handle_alloc_error(layout: Layout) -> ! {
        const fn ct_error(_: Layout) -> ! {
            panic!("allocation failed");
        }
    
        fn rt_error(layout: Layout) -> ! {
            unsafe {
                __rust_alloc_error_handler(layout.size(), layout.align());
            }
        }
    
        unsafe { core::intrinsics::const_eval_select((layout,), ct_error, rt_error) }
    }
    
    
    // https://github.com/torvalds/linux/blob/b6dad5178ceaf23f369c3711062ce1f2afc33644/rust/kernel/lib.rs#L96-L103
    fn panic(info: &core::panic::PanicInfo<'_>) -> ! {
        pr_emerg!("{}\n", info);
        // SAFETY: FFI call.
        unsafe { bindings::BUG() };
        // Bindgen currently does not recognize `__noreturn` so `BUG` returns `()`
        // instead of `!`. See <https://github.com/rust-lang/rust-bindgen/issues/2094>.
        loop {}
    }
    
    
    // https://github.com/torvalds/linux/blob/master/include/asm-generic/bug.h#L51-L68
    /*
     * Don't use BUG() or BUG_ON() unless there's really no way out; one
     * example might be detecting data structure corruption in the middle
     * of an operation that can't be backed out of.  If the (sub)system
     * can somehow continue operating, perhaps with reduced functionality,
     * it's probably not BUG-worthy.
     *
     * If you're tempted to BUG(), think again:  is completely giving up
     * really the *only* solution?  There are usually better options, where
     * users don't need to reboot ASAP and can mostly shut down cleanly.
     */
    #ifndef HAVE_ARCH_BUG
    #define BUG() do { \
    	printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
    	barrier_before_unreachable(); \
    	panic("BUG!"); \
    } while (0)
    #endif

    О том, как в ядре Linux говнораст обрабатывает ошибку аллокации

    j123123, 19 Июня 2023

    Комментарии (31)
  5. Си / Говнокод #28466

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    // https://github.com/flipperdevices/flipperzero-firmware/blob/2a6a3a1bf7ba1ecb42b8cbfc1b1856a54f2878b7/applications/plugins/music_player/music_player.c#L74
    
    static bool is_white_note(uint8_t semitone, uint8_t id) {
        switch(semitone) {
        case 0:
            if(id == 0) return true;
            break;
        case 2:
            if(id == 1) return true;
            break;
        case 4:
            if(id == 2) return true;
            break;
        case 5:
            if(id == 3) return true;
            break;
        case 7:
            if(id == 4) return true;
            break;
        case 9:
            if(id == 5) return true;
            break;
        case 11:
            if(id == 6) return true;
            break;
        default:
            break;
        }
    
        return false;
    }
    
    static bool is_black_note(uint8_t semitone, uint8_t id) {
        switch(semitone) {
        case 1:
            if(id == 0) return true;
            break;
        case 3:
            if(id == 1) return true;
            break;
        case 6:
            if(id == 3) return true;
            break;
        case 8:
            if(id == 4) return true;
            break;
        case 10:
            if(id == 5) return true;
            break;
        default:
            break;
        }
    
        return false;
    }

    Хуйня какая-то. То ли дело "паттерн матчинг".

    j123123, 01 Декабря 2022

    Комментарии (38)
  6. Си / Говнокод #28325

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    unsigned mul(unsigned a, unsigned b)
    {
     char arr[a][b];
     return &arr[a][b] - (char *)arr;
    }

    Умножение через VLA

    j123123, 09 Августа 2022

    Комментарии (59)
  7. Си / Говнокод #28309

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    #include <stdio.h>
    #include <string.h>
    #include <inttypes.h>
    
    void swap(uint8_t *x, uint8_t *y)
    {
        uint8_t tmp;
        tmp = *x;
        *x = *y;
        *y = tmp;
    }
    
    // эту хуйню тоже можно нагенерировать
    uint64_t cmp_bits(uint8_t a[restrict 9])
    {
      return 
      ((uint64_t)(a[0] < a[1]) << 0) |
      ((uint64_t)(a[0] < a[2]) << 1) |
      ((uint64_t)(a[0] < a[3]) << 2) |
      ((uint64_t)(a[0] < a[4]) << 3) |
      ((uint64_t)(a[0] < a[5]) << 4) |
      ((uint64_t)(a[0] < a[6]) << 5) |
      ((uint64_t)(a[0] < a[7]) << 6) |
      ((uint64_t)(a[0] < a[8]) << 7) |
    
      ((uint64_t)(a[1] < a[2]) << 8)  |
      ((uint64_t)(a[1] < a[3]) << 9)  |
      ((uint64_t)(a[1] < a[4]) << 10) |
      ((uint64_t)(a[1] < a[5]) << 11) |
      ((uint64_t)(a[1] < a[6]) << 12) |
      ((uint64_t)(a[1] < a[7]) << 13) |
      ((uint64_t)(a[1] < a[8]) << 14) |
    
      ((uint64_t)(a[2] < a[3]) << 15) |
      ((uint64_t)(a[2] < a[4]) << 16) |
      ((uint64_t)(a[2] < a[5]) << 17) |
      ((uint64_t)(a[2] < a[6]) << 18) |
      ((uint64_t)(a[2] < a[7]) << 19) |
      ((uint64_t)(a[2] < a[8]) << 20) |
    
      ((uint64_t)(a[3] < a[4]) << 21) |
      ((uint64_t)(a[3] < a[5]) << 22) |
      ((uint64_t)(a[3] < a[6]) << 23) |
      ((uint64_t)(a[3] < a[7]) << 24) |
      ((uint64_t)(a[3] < a[8]) << 25) |
    
      ((uint64_t)(a[4] < a[5]) << 26) |
      ((uint64_t)(a[4] < a[6]) << 27) |
      ((uint64_t)(a[4] < a[7]) << 28) |
      ((uint64_t)(a[4] < a[8]) << 29) |
    
      ((uint64_t)(a[5] < a[6]) << 30) |
      ((uint64_t)(a[5] < a[7]) << 31) |
      ((uint64_t)(a[5] < a[8]) << 32) |
    
      ((uint64_t)(a[6] < a[7]) << 33) |
      ((uint64_t)(a[6] < a[8]) << 34) |
    
      ((uint64_t)(a[7] < a[8]) << 35);
    }
    
    void printshit(uint8_t a[restrict 9])
    {
      size_t i = 0;
      while(*a != 4)
      {
        a++;
        i++;
      }
      printf("arr[%" PRIu64 "] = %zu\n", cmp_bits(a), i);
    }
    
    void permute(char *a, size_t l, size_t r)
    {
      size_t i;
      if (l == r)
        printshit(a);
      else
      {
        for (i = l; i <= r; i++)
        {
          swap((a+l), (a+i));
          permute(a, l+1, r);
          swap((a+l), (a+i));
        }
      }
    }
    
    int main()
    {
        uint8_t a[] = {0,1,2,3,4,5,6,7,8};
        size_t n = 9;
        permute(a, 0, n-1);
        return 0;
    }

    https://govnokod.ru/24496#comment782476

    Построение таблицы поиска для быстрого нахождения медианы. Там эту хуйню конечно можно улучшить, например запаковывать число от 0 до 8 в хуйни по 4 бита

    j123123, 31 Июля 2022

    Комментарии (55)
  8. C++ / Говнокод #28119

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    // https://github.com/gcc-mirror/gcc/blob/ec03862f809e544a9b7d28067e51597dc92a0244/libstdc%2B%2B-v3/include/bits/forward_list.tcc#L391-L411
    
      template<typename _Tp, typename _Alloc>
        bool
        operator==(const forward_list<_Tp, _Alloc>& __lx,
    	       const forward_list<_Tp, _Alloc>& __ly)
        {
          //  We don't have size() so we need to walk through both lists
          //  making sure both iterators are valid.
          auto __ix = __lx.cbegin();
          auto __iy = __ly.cbegin();
          while (__ix != __lx.cend() && __iy != __ly.cend())
    	{
    	  if (!(*__ix == *__iy))
    	    return false;
    	  ++__ix;
    	  ++__iy;
    	}
          if (__ix == __lx.cend() && __iy == __ly.cend())
    	return true;
          else
    	return false;
        }

    из стандартной библиотеки крестоговна от GCC

    j123123, 13 Апреля 2022

    Комментарии (54)
  9. C++ / Говнокод #28109

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    // https://github.com/santiontanon/stransball2/blob/dff413c6ed236b4be23e0152557a26d7d902976c/sources/state_changepack.cpp#L67
    
    bool state_changepack_cycle(SDL_Surface *screen,int sx,int sy,unsigned char *keyboard)
    {
    	if (SUBSTATE==0) {
    		if (image!=0) SDL_FreeSurface(image);
    		image=IMG_Load("graphics/tittle.pcx");
    
    		{
    			levelpacks.Delete();
                                                             
    #ifdef _WIN32
                            /* Find files: */ 
                            WIN32_FIND_DATA finfo;
                            HANDLE h;
    
                            h=FindFirstFile("maps/*.lp",&finfo);
                            if (h!=INVALID_HANDLE_VALUE) {
                                    char *tmp;
    
                                    tmp=new char[strlen(finfo.cFileName)+1];
                                    strcpy(tmp,finfo.cFileName);
                                    levelpacks.Add(tmp);
    
                                    while(FindNextFile(h,&finfo)==TRUE) {
                                        char *tmp;
    
                                        tmp=new char[strlen(finfo.cFileName)+1];
                                        strcpy(tmp,finfo.cFileName);
                                        levelpacks.Add(tmp);
                                    } /* while */ 
                            } /* if */ 
    #else
                            DIR *dp;
                            struct dirent *ep;
    		  
                            dp = opendir ("maps");
                            if (dp != NULL)
                            {
                                while (ep = readdir (dp))
                                {
                                    char *tmp;
                             
                                    if (strlen(ep->d_name)>4 &&
                                        ep->d_name[strlen(ep->d_name)-3]=='.' &&
                                        ep->d_name[strlen(ep->d_name)-2]=='l' &&
                                        ep->d_name[strlen(ep->d_name)-1]=='p') {
                                        tmp=new char[strlen(ep->d_name)+1];
                                        strcpy(tmp,ep->d_name);
                                        levelpacks.Add(tmp);                                    
                                    } /* if */
                                   
                                }
                                (void) closedir (dp);
                            }
    #endif

    Super Transball 2 (супер трансшары 2)

    j123123, 04 Апреля 2022

    Комментарии (44)
  10. Pascal / Говнокод #27987

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    Dim a As Double
    	'обнуление видимой величины
    Private Sub Command1_Click()
        		Dim b As Double
        		Dim c As Double
      
        		b = Val(Replace(Text2.Text, ",", "."))
        		c = a - b
       		 Text3.Text = c
    End Sub
    
    Private Sub Form_Load()
    		'ввод числа 3FBF9ADD3746F67D 
         		a = 0.123456789012346 + 1E-16
        		Text1.Text = a
    End Sub

    Источник - https://www.softelectro.ru/ieee754.html

    j123123, 03 Февраля 2022

    Комментарии (92)
  11. Си / Говнокод #27983

    0

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    // https://sources.debian.org/src/bsdiff/4.3-23/bsdiff.c/#L57
    
    static void split(t_off *I,t_off *V,t_off start,t_off len,t_off h)
    {
    	t_off i,j,k,x,tmp,jj,kk;
    
    	if(len<16) {
    		for(k=start;k<start+len;k+=j) {
    			j=1;x=V[I[k]+h];
    			for(i=1;k+i<start+len;i++) {
    				if(V[I[k+i]+h]<x) {
    					x=V[I[k+i]+h];
    					j=0;
    				};
    				if(V[I[k+i]+h]==x) {
    					tmp=I[k+j];I[k+j]=I[k+i];I[k+i]=tmp;
    					j++;
    				};
    			};
    			for(i=0;i<j;i++) V[I[k+i]]=k+j-1;
    			if(j==1) I[k]=-1;
    		};
    		return;
    	};
    
    	x=V[I[start+len/2]+h];
    	jj=0;kk=0;
    	for(i=start;i<start+len;i++) {
    		if(V[I[i]+h]<x) jj++;
    		if(V[I[i]+h]==x) kk++;
    	};
    	jj+=start;kk+=jj;
    
    	i=start;j=0;k=0;
    	while(i<jj) {
    		if(V[I[i]+h]<x) {
    			i++;
    		} else if(V[I[i]+h]==x) {
    			tmp=I[i];I[i]=I[jj+j];I[jj+j]=tmp;
    			j++;
    		} else {
    			tmp=I[i];I[i]=I[kk+k];I[kk+k]=tmp;
    			k++;
    		};
    	};
    
    	while(jj+j<kk) {
    		if(V[I[jj+j]+h]==x) {
    			j++;
    		} else {
    			tmp=I[jj+j];I[jj+j]=I[kk+k];I[kk+k]=tmp;
    			k++;
    		};
    	};
    
    	if(jj>start) split(I,V,start,jj-start,h);
    
    	for(i=0;i<kk-jj;i++) V[I[jj+i]]=kk-1;
    	if(jj==kk-1) I[jj]=-1;
    
    	if(start+len>kk) split(I,V,kk,start+len-kk,h);
    }
    
    static void qsufsort(t_off *I,t_off *V,u_char *old,t_off oldsize)
    {
    	t_off buckets[256];
    	t_off i,h,len;
    
    	for(i=0;i<256;i++) buckets[i]=0;
    	for(i=0;i<oldsize;i++) buckets[old[i]]++;
    	for(i=1;i<256;i++) buckets[i]+=buckets[i-1];
    	for(i=255;i>0;i--) buckets[i]=buckets[i-1];
    	buckets[0]=0;
    
    	for(i=0;i<oldsize;i++) I[++buckets[old[i]]]=i;
    	I[0]=oldsize;
    	for(i=0;i<oldsize;i++) V[i]=buckets[old[i]];
    	V[oldsize]=0;
    	for(i=1;i<256;i++) if(buckets[i]==buckets[i-1]+1) I[buckets[i]]=-1;
    	I[0]=-1;
    
    	for(h=1;I[0]!=-(oldsize+1);h+=h) {
    		len=0;
    		for(i=0;i<oldsize+1;) {
    			if(I[i]<0) {
    				len-=I[i];
    				i-=I[i];
    			} else {
    				if(len) I[i-len]=-len;
    				len=V[I[i]]+1-i;
    				split(I,V,i,len,h);
    				i+=len;
    				len=0;
    			};
    		};
    		if(len) I[i-len]=-len;
    	};
    
    	for(i=0;i<oldsize+1;i++) I[V[i]]=i;
    }

    Исходник "bsdiff"

    j123123, 02 Февраля 2022

    Комментарии (43)