• R/O
  • SSH
  • HTTPS

cstl: Commit


Commit MetaInfo

Revision193 (tree)
Time2008-01-20 23:49:36
Authorkatono

Log Message

(empty log message)

Change Summary

Incremental Difference

--- trunk/test/algo_test.cpp (revision 192)
+++ trunk/test/algo_test.cpp (revision 193)
@@ -32,7 +32,7 @@
3232 #endif
3333
3434 #define SORT_COUNT (1000000)
35-#define SEARCH_COUNT (1000)
35+#define COUNT (1000)
3636 using namespace std;
3737
3838
@@ -600,74 +600,74 @@
600600 IntVector *x;
601601 int i;
602602 printf("***** test_2_1 *****\n");
603- x = IntVector_new(SEARCH_COUNT);
603+ x = IntVector_new(COUNT);
604604 assert(x);
605- for (i = 0; i < SEARCH_COUNT; i++) {
605+ for (i = 0; i < COUNT; i++) {
606606 assert(IntVector_push_back(x, i));
607607 }
608- assert(IntVector_size(x) == SEARCH_COUNT);
608+ assert(IntVector_size(x) == COUNT);
609609 // binary_search
610610 // idx:0からsize()個
611611 assert(0 == IntVector_binary_search(x, 0, IntVector_size(x), 0, int_less));
612- assert(SEARCH_COUNT - 1 == IntVector_binary_search(x, 0, IntVector_size(x), SEARCH_COUNT - 1, int_less));
613- assert(SEARCH_COUNT / 2 == IntVector_binary_search(x, 0, IntVector_size(x), SEARCH_COUNT / 2, int_less));
614- assert(SEARCH_COUNT / 3 == IntVector_binary_search(x, 0, IntVector_size(x), SEARCH_COUNT / 3, int_less));
615- assert(SEARCH_COUNT == IntVector_binary_search(x, 0, IntVector_size(x), SEARCH_COUNT, int_less));
616- assert(SEARCH_COUNT == IntVector_binary_search(x, 0, IntVector_size(x), SEARCH_COUNT + 1, int_less));
612+ assert(COUNT - 1 == IntVector_binary_search(x, 0, IntVector_size(x), COUNT - 1, int_less));
613+ assert(COUNT / 2 == IntVector_binary_search(x, 0, IntVector_size(x), COUNT / 2, int_less));
614+ assert(COUNT / 3 == IntVector_binary_search(x, 0, IntVector_size(x), COUNT / 3, int_less));
615+ assert(COUNT == IntVector_binary_search(x, 0, IntVector_size(x), COUNT, int_less));
616+ assert(COUNT == IntVector_binary_search(x, 0, IntVector_size(x), COUNT + 1, int_less));
617617 // idx:1からsize() - 1個
618- assert(SEARCH_COUNT == IntVector_binary_search(x, 1, IntVector_size(x) - 1, 0, int_less));
619- assert(SEARCH_COUNT - 1 == IntVector_binary_search(x, 1, IntVector_size(x) - 1, SEARCH_COUNT - 1, int_less));
620- assert(SEARCH_COUNT / 2 == IntVector_binary_search(x, 1, IntVector_size(x) - 1, SEARCH_COUNT / 2, int_less));
621- assert(SEARCH_COUNT / 3 == IntVector_binary_search(x, 1, IntVector_size(x) - 1, SEARCH_COUNT / 3, int_less));
622- assert(SEARCH_COUNT == IntVector_binary_search(x, 1, IntVector_size(x) - 1, SEARCH_COUNT, int_less));
623- assert(SEARCH_COUNT == IntVector_binary_search(x, 1, IntVector_size(x) - 1, SEARCH_COUNT + 1, int_less));
618+ assert(COUNT == IntVector_binary_search(x, 1, IntVector_size(x) - 1, 0, int_less));
619+ assert(COUNT - 1 == IntVector_binary_search(x, 1, IntVector_size(x) - 1, COUNT - 1, int_less));
620+ assert(COUNT / 2 == IntVector_binary_search(x, 1, IntVector_size(x) - 1, COUNT / 2, int_less));
621+ assert(COUNT / 3 == IntVector_binary_search(x, 1, IntVector_size(x) - 1, COUNT / 3, int_less));
622+ assert(COUNT == IntVector_binary_search(x, 1, IntVector_size(x) - 1, COUNT, int_less));
623+ assert(COUNT == IntVector_binary_search(x, 1, IntVector_size(x) - 1, COUNT + 1, int_less));
624624
625625 // lower_bound
626626 // idx:0からsize()個
627627 assert(0 == IntVector_lower_bound(x, 0, IntVector_size(x), 0, int_less));
628- assert(SEARCH_COUNT - 1 == IntVector_lower_bound(x, 0, IntVector_size(x), SEARCH_COUNT - 1, int_less));
629- assert(SEARCH_COUNT / 2 == IntVector_lower_bound(x, 0, IntVector_size(x), SEARCH_COUNT / 2, int_less));
630- assert(SEARCH_COUNT / 3 == IntVector_lower_bound(x, 0, IntVector_size(x), SEARCH_COUNT / 3, int_less));
631- assert(SEARCH_COUNT == IntVector_lower_bound(x, 0, IntVector_size(x), SEARCH_COUNT, int_less));
632- assert(SEARCH_COUNT == IntVector_lower_bound(x, 0, IntVector_size(x), SEARCH_COUNT + 1, int_less));
628+ assert(COUNT - 1 == IntVector_lower_bound(x, 0, IntVector_size(x), COUNT - 1, int_less));
629+ assert(COUNT / 2 == IntVector_lower_bound(x, 0, IntVector_size(x), COUNT / 2, int_less));
630+ assert(COUNT / 3 == IntVector_lower_bound(x, 0, IntVector_size(x), COUNT / 3, int_less));
631+ assert(COUNT == IntVector_lower_bound(x, 0, IntVector_size(x), COUNT, int_less));
632+ assert(COUNT == IntVector_lower_bound(x, 0, IntVector_size(x), COUNT + 1, int_less));
633633 // idx:1からsize() - 1個
634634 assert(1 == IntVector_lower_bound(x, 1, IntVector_size(x) - 1, 0, int_less));
635- assert(SEARCH_COUNT - 1 == IntVector_lower_bound(x, 1, IntVector_size(x) - 1, SEARCH_COUNT - 1, int_less));
636- assert(SEARCH_COUNT / 2 == IntVector_lower_bound(x, 1, IntVector_size(x) - 1, SEARCH_COUNT / 2, int_less));
637- assert(SEARCH_COUNT / 3 == IntVector_lower_bound(x, 1, IntVector_size(x) - 1, SEARCH_COUNT / 3, int_less));
638- assert(SEARCH_COUNT == IntVector_lower_bound(x, 1, IntVector_size(x) - 1, SEARCH_COUNT, int_less));
639- assert(SEARCH_COUNT == IntVector_lower_bound(x, 1, IntVector_size(x) - 1, SEARCH_COUNT + 1, int_less));
635+ assert(COUNT - 1 == IntVector_lower_bound(x, 1, IntVector_size(x) - 1, COUNT - 1, int_less));
636+ assert(COUNT / 2 == IntVector_lower_bound(x, 1, IntVector_size(x) - 1, COUNT / 2, int_less));
637+ assert(COUNT / 3 == IntVector_lower_bound(x, 1, IntVector_size(x) - 1, COUNT / 3, int_less));
638+ assert(COUNT == IntVector_lower_bound(x, 1, IntVector_size(x) - 1, COUNT, int_less));
639+ assert(COUNT == IntVector_lower_bound(x, 1, IntVector_size(x) - 1, COUNT + 1, int_less));
640640
641641 // upper_bound
642642 // idx:0からsize()個
643643 assert(1 == IntVector_upper_bound(x, 0, IntVector_size(x), 0, int_less));
644- assert(SEARCH_COUNT - 1 == IntVector_upper_bound(x, 0, IntVector_size(x), SEARCH_COUNT - 2, int_less));
645- assert(SEARCH_COUNT == IntVector_upper_bound(x, 0, IntVector_size(x), SEARCH_COUNT - 1, int_less));
646- assert(SEARCH_COUNT / 2 + 1 == IntVector_upper_bound(x, 0, IntVector_size(x), SEARCH_COUNT / 2, int_less));
647- assert(SEARCH_COUNT / 3 + 1 == IntVector_upper_bound(x, 0, IntVector_size(x), SEARCH_COUNT / 3, int_less));
648- assert(SEARCH_COUNT == IntVector_upper_bound(x, 0, IntVector_size(x), SEARCH_COUNT, int_less));
649- assert(SEARCH_COUNT == IntVector_upper_bound(x, 0, IntVector_size(x), SEARCH_COUNT + 1, int_less));
644+ assert(COUNT - 1 == IntVector_upper_bound(x, 0, IntVector_size(x), COUNT - 2, int_less));
645+ assert(COUNT == IntVector_upper_bound(x, 0, IntVector_size(x), COUNT - 1, int_less));
646+ assert(COUNT / 2 + 1 == IntVector_upper_bound(x, 0, IntVector_size(x), COUNT / 2, int_less));
647+ assert(COUNT / 3 + 1 == IntVector_upper_bound(x, 0, IntVector_size(x), COUNT / 3, int_less));
648+ assert(COUNT == IntVector_upper_bound(x, 0, IntVector_size(x), COUNT, int_less));
649+ assert(COUNT == IntVector_upper_bound(x, 0, IntVector_size(x), COUNT + 1, int_less));
650650 // idx:1からsize() - 1個
651651 assert(1 == IntVector_upper_bound(x, 1, IntVector_size(x) - 1, 0, int_less));
652- assert(SEARCH_COUNT - 1 == IntVector_upper_bound(x, 1, IntVector_size(x) - 1, SEARCH_COUNT - 2, int_less));
653- assert(SEARCH_COUNT == IntVector_upper_bound(x, 1, IntVector_size(x) - 1, SEARCH_COUNT - 1, int_less));
654- assert(SEARCH_COUNT / 2 + 1 == IntVector_upper_bound(x, 1, IntVector_size(x) - 1, SEARCH_COUNT / 2, int_less));
655- assert(SEARCH_COUNT / 3 + 1 == IntVector_upper_bound(x, 1, IntVector_size(x) - 1, SEARCH_COUNT / 3, int_less));
656- assert(SEARCH_COUNT == IntVector_upper_bound(x, 1, IntVector_size(x) - 1, SEARCH_COUNT, int_less));
657- assert(SEARCH_COUNT == IntVector_upper_bound(x, 1, IntVector_size(x) - 1, SEARCH_COUNT + 1, int_less));
652+ assert(COUNT - 1 == IntVector_upper_bound(x, 1, IntVector_size(x) - 1, COUNT - 2, int_less));
653+ assert(COUNT == IntVector_upper_bound(x, 1, IntVector_size(x) - 1, COUNT - 1, int_less));
654+ assert(COUNT / 2 + 1 == IntVector_upper_bound(x, 1, IntVector_size(x) - 1, COUNT / 2, int_less));
655+ assert(COUNT / 3 + 1 == IntVector_upper_bound(x, 1, IntVector_size(x) - 1, COUNT / 3, int_less));
656+ assert(COUNT == IntVector_upper_bound(x, 1, IntVector_size(x) - 1, COUNT, int_less));
657+ assert(COUNT == IntVector_upper_bound(x, 1, IntVector_size(x) - 1, COUNT + 1, int_less));
658658
659659
660- *IntVector_at(x, SEARCH_COUNT / 2) = *IntVector_at(x, SEARCH_COUNT / 2 + 1);
660+ *IntVector_at(x, COUNT / 2) = *IntVector_at(x, COUNT / 2 + 1);
661661
662662 // binary_search
663- assert(SEARCH_COUNT == IntVector_binary_search(x, 0, IntVector_size(x), SEARCH_COUNT / 2, int_less));
664- assert(SEARCH_COUNT / 2 == IntVector_binary_search(x, 0, IntVector_size(x), SEARCH_COUNT / 2 + 1, int_less));
663+ assert(COUNT == IntVector_binary_search(x, 0, IntVector_size(x), COUNT / 2, int_less));
664+ assert(COUNT / 2 == IntVector_binary_search(x, 0, IntVector_size(x), COUNT / 2 + 1, int_less));
665665 // lower_bound
666- assert(SEARCH_COUNT / 2 == IntVector_lower_bound(x, 0, IntVector_size(x), SEARCH_COUNT / 2, int_less));
667- assert(SEARCH_COUNT / 2 == IntVector_lower_bound(x, 0, IntVector_size(x), SEARCH_COUNT / 2 + 1, int_less));
666+ assert(COUNT / 2 == IntVector_lower_bound(x, 0, IntVector_size(x), COUNT / 2, int_less));
667+ assert(COUNT / 2 == IntVector_lower_bound(x, 0, IntVector_size(x), COUNT / 2 + 1, int_less));
668668 // upper_bound
669- assert(SEARCH_COUNT / 2 == IntVector_upper_bound(x, 0, IntVector_size(x), SEARCH_COUNT / 2, int_less));
670- assert(SEARCH_COUNT / 2 + 2 == IntVector_upper_bound(x, 0, IntVector_size(x), SEARCH_COUNT / 2 + 1, int_less));
669+ assert(COUNT / 2 == IntVector_upper_bound(x, 0, IntVector_size(x), COUNT / 2, int_less));
670+ assert(COUNT / 2 + 2 == IntVector_upper_bound(x, 0, IntVector_size(x), COUNT / 2 + 1, int_less));
671671
672672
673673 IntVector_delete(x);
@@ -678,37 +678,37 @@
678678 IntVector *x;
679679 int i;
680680 printf("***** test_3_1 *****\n");
681- x = IntVector_new(SEARCH_COUNT);
681+ x = IntVector_new(COUNT);
682682 assert(x);
683- for (i = 0; i < SEARCH_COUNT; i++) {
683+ for (i = 0; i < COUNT; i++) {
684684 assert(IntVector_push_back(x, i));
685685 }
686- assert(IntVector_size(x) == SEARCH_COUNT);
686+ assert(IntVector_size(x) == COUNT);
687687 // reverse
688688 IntVector_reverse(x, 0, IntVector_size(x));
689- for (i = 0; i < SEARCH_COUNT; i++) {
690- assert(*IntVector_at(x, i) == SEARCH_COUNT - 1 - i);
689+ for (i = 0; i < COUNT; i++) {
690+ assert(*IntVector_at(x, i) == COUNT - 1 - i);
691691 }
692- assert(IntVector_size(x) == SEARCH_COUNT);
692+ assert(IntVector_size(x) == COUNT);
693693
694694 // reverse
695695 IntVector_reverse(x, 0, IntVector_size(x));
696- for (i = 0; i < SEARCH_COUNT; i++) {
696+ for (i = 0; i < COUNT; i++) {
697697 assert(*IntVector_at(x, i) == i);
698698 }
699- assert(IntVector_size(x) == SEARCH_COUNT);
699+ assert(IntVector_size(x) == COUNT);
700700
701701 // 途中からreverse
702- IntVector_reverse(x, SEARCH_COUNT / 2, IntVector_size(x) - SEARCH_COUNT / 2);
703- for (i = 0; i < SEARCH_COUNT; i++) {
702+ IntVector_reverse(x, COUNT / 2, IntVector_size(x) - COUNT / 2);
703+ for (i = 0; i < COUNT; i++) {
704704 // printf("i[%d], data[%d]\n", i, *IntVector_at(x, i));
705- if (i < SEARCH_COUNT / 2) {
705+ if (i < COUNT / 2) {
706706 assert(*IntVector_at(x, i) == i);
707707 } else {
708- assert(*IntVector_at(x, i) == SEARCH_COUNT - 1 - (i - SEARCH_COUNT / 2));
708+ assert(*IntVector_at(x, i) == COUNT - 1 - (i - COUNT / 2));
709709 }
710710 }
711- assert(IntVector_size(x) == SEARCH_COUNT);
711+ assert(IntVector_size(x) == COUNT);
712712
713713 IntVector_delete(x);
714714 }
@@ -718,48 +718,48 @@
718718 IntVector *x;
719719 int i;
720720 printf("***** test_3_2 *****\n");
721- x = IntVector_new(SEARCH_COUNT);
721+ x = IntVector_new(COUNT);
722722 assert(x);
723- for (i = 0; i < SEARCH_COUNT; i++) {
723+ for (i = 0; i < COUNT; i++) {
724724 assert(IntVector_push_back(x, i));
725725 }
726- assert(IntVector_size(x) == SEARCH_COUNT);
726+ assert(IntVector_size(x) == COUNT);
727727 // rotate
728728 IntVector_rotate(x, 0, 0, 0);
729- for (i = 0; i < SEARCH_COUNT; i++) {
729+ for (i = 0; i < COUNT; i++) {
730730 assert(*IntVector_at(x, i) == i);
731731 }
732- assert(IntVector_size(x) == SEARCH_COUNT);
733- IntVector_rotate(x, SEARCH_COUNT / 2, SEARCH_COUNT / 2, SEARCH_COUNT / 2);
734- for (i = 0; i < SEARCH_COUNT; i++) {
732+ assert(IntVector_size(x) == COUNT);
733+ IntVector_rotate(x, COUNT / 2, COUNT / 2, COUNT / 2);
734+ for (i = 0; i < COUNT; i++) {
735735 assert(*IntVector_at(x, i) == i);
736736 }
737- assert(IntVector_size(x) == SEARCH_COUNT);
738- IntVector_rotate(x, SEARCH_COUNT, SEARCH_COUNT, SEARCH_COUNT);
739- for (i = 0; i < SEARCH_COUNT; i++) {
737+ assert(IntVector_size(x) == COUNT);
738+ IntVector_rotate(x, COUNT, COUNT, COUNT);
739+ for (i = 0; i < COUNT; i++) {
740740 assert(*IntVector_at(x, i) == i);
741741 }
742- assert(IntVector_size(x) == SEARCH_COUNT);
743- IntVector_rotate(x, 0, SEARCH_COUNT, SEARCH_COUNT);
744- for (i = 0; i < SEARCH_COUNT; i++) {
742+ assert(IntVector_size(x) == COUNT);
743+ IntVector_rotate(x, 0, COUNT, COUNT);
744+ for (i = 0; i < COUNT; i++) {
745745 assert(*IntVector_at(x, i) == i);
746746 }
747- assert(IntVector_size(x) == SEARCH_COUNT);
748- IntVector_rotate(x, 0, 0, SEARCH_COUNT);
749- for (i = 0; i < SEARCH_COUNT; i++) {
747+ assert(IntVector_size(x) == COUNT);
748+ IntVector_rotate(x, 0, 0, COUNT);
749+ for (i = 0; i < COUNT; i++) {
750750 assert(*IntVector_at(x, i) == i);
751751 }
752- assert(IntVector_size(x) == SEARCH_COUNT);
752+ assert(IntVector_size(x) == COUNT);
753753
754- IntVector_rotate(x, 0, SEARCH_COUNT / 2, SEARCH_COUNT);
755- for (i = 0; i < SEARCH_COUNT; i++) {
756- if (i < SEARCH_COUNT / 2) {
757- assert(*IntVector_at(x, i) == i + SEARCH_COUNT / 2);
754+ IntVector_rotate(x, 0, COUNT / 2, COUNT);
755+ for (i = 0; i < COUNT; i++) {
756+ if (i < COUNT / 2) {
757+ assert(*IntVector_at(x, i) == i + COUNT / 2);
758758 } else {
759- assert(*IntVector_at(x, i) == i - SEARCH_COUNT / 2);
759+ assert(*IntVector_at(x, i) == i - COUNT / 2);
760760 }
761761 }
762- assert(IntVector_size(x) == SEARCH_COUNT);
762+ assert(IntVector_size(x) == COUNT);
763763
764764 IntVector_delete(x);
765765 }
@@ -771,70 +771,70 @@
771771 IntVector *z;
772772 int i;
773773 printf("***** test_4_1 *****\n");
774- x = IntVector_new(SEARCH_COUNT);
775- y = IntVector_new(SEARCH_COUNT);
776- z = IntVector_new(SEARCH_COUNT);
774+ x = IntVector_new(COUNT);
775+ y = IntVector_new(COUNT);
776+ z = IntVector_new(COUNT);
777777 assert(x);
778778 assert(y);
779779 assert(z);
780- for (i = 0; i < SEARCH_COUNT / 2; i++) {
780+ for (i = 0; i < COUNT / 2; i++) {
781781 assert(IntVector_push_back(x, i * 2));
782782 }
783- assert(IntVector_size(x) == SEARCH_COUNT / 2);
784- for (i = 0; i < SEARCH_COUNT / 2; i++) {
783+ assert(IntVector_size(x) == COUNT / 2);
784+ for (i = 0; i < COUNT / 2; i++) {
785785 assert(IntVector_push_back(y, i * 2 + 1));
786786 }
787- assert(IntVector_size(y) == SEARCH_COUNT / 2);
787+ assert(IntVector_size(y) == COUNT / 2);
788788
789789 // merge
790790 assert(IntVector_merge(z, 0, x, 0, IntVector_size(x), y, 0, IntVector_size(y), int_less));
791- assert(IntVector_size(x) == SEARCH_COUNT / 2);
792- assert(IntVector_size(y) == SEARCH_COUNT / 2);
793- assert(IntVector_size(z) == SEARCH_COUNT);
794- for (i = 0; i < SEARCH_COUNT; i++) {
791+ assert(IntVector_size(x) == COUNT / 2);
792+ assert(IntVector_size(y) == COUNT / 2);
793+ assert(IntVector_size(z) == COUNT);
794+ for (i = 0; i < COUNT; i++) {
795795 assert(*IntVector_at(z, i) == i);
796796 }
797797
798798 assert(IntVector_merge(z, IntVector_size(z), x, 0, IntVector_size(x), y, 0, IntVector_size(y), int_less));
799- assert(IntVector_size(z) == SEARCH_COUNT * 2);
800- for (i = 0; i < SEARCH_COUNT; i++) {
799+ assert(IntVector_size(z) == COUNT * 2);
800+ for (i = 0; i < COUNT; i++) {
801801 assert(*IntVector_at(z, i) == i);
802802 }
803- for (i = 0; i < SEARCH_COUNT; i++) {
804- assert(*IntVector_at(z, i + SEARCH_COUNT) == i);
803+ for (i = 0; i < COUNT; i++) {
804+ assert(*IntVector_at(z, i + COUNT) == i);
805805 }
806806
807- for (i = 0; i < SEARCH_COUNT / 2; i++) {
807+ for (i = 0; i < COUNT / 2; i++) {
808808 *IntVector_at(x, i) = *IntVector_at(x, i) * 2;
809809 *IntVector_at(y, i) = *IntVector_at(y, i) * 2;
810810 }
811- assert(IntVector_merge(z, SEARCH_COUNT, x, 0, IntVector_size(x), y, 0, IntVector_size(y), int_less));
812- assert(IntVector_size(z) == SEARCH_COUNT * 3);
813- for (i = 0; i < SEARCH_COUNT; i++) {
811+ assert(IntVector_merge(z, COUNT, x, 0, IntVector_size(x), y, 0, IntVector_size(y), int_less));
812+ assert(IntVector_size(z) == COUNT * 3);
813+ for (i = 0; i < COUNT; i++) {
814814 assert(*IntVector_at(z, i) == i);
815815 }
816- for (i = 0; i < SEARCH_COUNT; i++) {
817-// printf("i[%d], idx[%d], at[%d]\n", i, i + SEARCH_COUNT, *IntVector_at(z, i + SEARCH_COUNT));
818- assert(*IntVector_at(z, i + SEARCH_COUNT) == i * 2);
816+ for (i = 0; i < COUNT; i++) {
817+// printf("i[%d], idx[%d], at[%d]\n", i, i + COUNT, *IntVector_at(z, i + COUNT));
818+ assert(*IntVector_at(z, i + COUNT) == i * 2);
819819 }
820- for (i = 0; i < SEARCH_COUNT; i++) {
821- assert(*IntVector_at(z, i + SEARCH_COUNT * 2) == i);
820+ for (i = 0; i < COUNT; i++) {
821+ assert(*IntVector_at(z, i + COUNT * 2) == i);
822822 }
823823
824824 #ifdef MY_MALLOC
825825 IntVector_shrink(z, 0);
826826 HEAP_SET_FAIL_COUNT(&heap, 0);
827- assert(!IntVector_merge(z, SEARCH_COUNT, x, 0, IntVector_size(x), y, 0, IntVector_size(y), int_less));
828- assert(IntVector_size(z) == SEARCH_COUNT * 3);
829- for (i = 0; i < SEARCH_COUNT; i++) {
827+ assert(!IntVector_merge(z, COUNT, x, 0, IntVector_size(x), y, 0, IntVector_size(y), int_less));
828+ assert(IntVector_size(z) == COUNT * 3);
829+ for (i = 0; i < COUNT; i++) {
830830 assert(*IntVector_at(z, i) == i);
831831 }
832- for (i = 0; i < SEARCH_COUNT; i++) {
833-// printf("i[%d], idx[%d], at[%d]\n", i, i + SEARCH_COUNT, *IntVector_at(z, i + SEARCH_COUNT));
834- assert(*IntVector_at(z, i + SEARCH_COUNT) == i * 2);
832+ for (i = 0; i < COUNT; i++) {
833+// printf("i[%d], idx[%d], at[%d]\n", i, i + COUNT, *IntVector_at(z, i + COUNT));
834+ assert(*IntVector_at(z, i + COUNT) == i * 2);
835835 }
836- for (i = 0; i < SEARCH_COUNT; i++) {
837- assert(*IntVector_at(z, i + SEARCH_COUNT * 2) == i);
836+ for (i = 0; i < COUNT; i++) {
837+ assert(*IntVector_at(z, i + COUNT * 2) == i);
838838 }
839839
840840
@@ -851,29 +851,29 @@
851851 IntVector *x;
852852 int i;
853853 printf("***** test_5_1 *****\n");
854- x = IntVector_new(SEARCH_COUNT);
854+ x = IntVector_new(COUNT);
855855 assert(x);
856856 // inplace_merge
857- for (i = 0; i < SEARCH_COUNT / 2; i++) {
857+ for (i = 0; i < COUNT / 2; i++) {
858858 assert(IntVector_push_back(x, i * 2));
859859 }
860- for (i = 0; i < SEARCH_COUNT / 2; i++) {
860+ for (i = 0; i < COUNT / 2; i++) {
861861 assert(IntVector_push_back(x, i * 2 + 1));
862862 }
863- assert(IntVector_size(x) == SEARCH_COUNT);
863+ assert(IntVector_size(x) == COUNT);
864864
865865 IntVector_inplace_merge(x, 0, IntVector_size(x) / 2, IntVector_size(x), int_less);
866- for (i = 0; i < SEARCH_COUNT; i++) {
866+ for (i = 0; i < COUNT; i++) {
867867 assert(*IntVector_at(x, i) == i);
868868 }
869- assert(IntVector_size(x) == SEARCH_COUNT);
869+ assert(IntVector_size(x) == COUNT);
870870
871871 IntVector_clear(x);
872872 srand(time(0));
873- for (i = 0; i < SEARCH_COUNT; i++) {
874- IntVector_push_back(x, rand() % SEARCH_COUNT);
873+ for (i = 0; i < COUNT; i++) {
874+ IntVector_push_back(x, rand() % COUNT);
875875 }
876- assert(IntVector_size(x) == SEARCH_COUNT);
876+ assert(IntVector_size(x) == COUNT);
877877
878878 IntVector_sort(x, 0, IntVector_size(x) / 2, int_less);
879879 IntVector_sort(x, IntVector_size(x) / 2, IntVector_size(x) / 2, int_less);
@@ -880,7 +880,7 @@
880880 int prev;
881881
882882 prev = 0;
883- for (i = 0; i < SEARCH_COUNT / 2; i++) {
883+ for (i = 0; i < COUNT / 2; i++) {
884884 // printf("%d ", *IntVector_at(x, i));
885885 assert(*IntVector_at(x, i) >= prev);
886886 prev = *IntVector_at(x, i);
@@ -887,23 +887,23 @@
887887 }
888888 printf("\n");
889889 prev = 0;
890- for (i = 0; i < SEARCH_COUNT / 2; i++) {
891-// printf("%d ", *IntVector_at(x, i + SEARCH_COUNT / 2));
892- assert(*IntVector_at(x, i + SEARCH_COUNT / 2) >= prev);
893- prev = *IntVector_at(x, i + SEARCH_COUNT / 2);
890+ for (i = 0; i < COUNT / 2; i++) {
891+// printf("%d ", *IntVector_at(x, i + COUNT / 2));
892+ assert(*IntVector_at(x, i + COUNT / 2) >= prev);
893+ prev = *IntVector_at(x, i + COUNT / 2);
894894 }
895895 printf("\n");
896- assert(IntVector_size(x) == SEARCH_COUNT);
896+ assert(IntVector_size(x) == COUNT);
897897
898898 IntVector_inplace_merge(x, 0, IntVector_size(x) / 2, IntVector_size(x), int_less);
899899 prev = 0;
900- for (i = 0; i < SEARCH_COUNT; i++) {
900+ for (i = 0; i < COUNT; i++) {
901901 // printf("%d ", *IntVector_at(x, i));
902902 assert(*IntVector_at(x, i) >= prev);
903903 prev = *IntVector_at(x, i);
904904 }
905905 printf("\n");
906- assert(IntVector_size(x) == SEARCH_COUNT);
906+ assert(IntVector_size(x) == COUNT);
907907
908908
909909 IntVector_delete(x);
@@ -915,31 +915,31 @@
915915 IntVector *x;
916916 int i;
917917 printf("***** test_5_2 *****\n");
918- x = IntVector_new(SEARCH_COUNT);
918+ x = IntVector_new(COUNT);
919919 assert(x);
920920 // inplace_merge
921921 // merge_without_buffer
922- for (i = 0; i < SEARCH_COUNT / 2; i++) {
922+ for (i = 0; i < COUNT / 2; i++) {
923923 assert(IntVector_push_back(x, i * 2));
924924 }
925- for (i = 0; i < SEARCH_COUNT / 2; i++) {
925+ for (i = 0; i < COUNT / 2; i++) {
926926 assert(IntVector_push_back(x, i * 2 + 1));
927927 }
928- assert(IntVector_size(x) == SEARCH_COUNT);
928+ assert(IntVector_size(x) == COUNT);
929929
930930 HEAP_SET_FAIL_COUNT(&heap, 0);
931931 IntVector_inplace_merge(x, 0, IntVector_size(x) / 2, IntVector_size(x), int_less);
932- for (i = 0; i < SEARCH_COUNT; i++) {
932+ for (i = 0; i < COUNT; i++) {
933933 assert(*IntVector_at(x, i) == i);
934934 }
935- assert(IntVector_size(x) == SEARCH_COUNT);
935+ assert(IntVector_size(x) == COUNT);
936936
937937 IntVector_clear(x);
938938 srand(time(0));
939- for (i = 0; i < SEARCH_COUNT; i++) {
940- IntVector_push_back(x, rand() % SEARCH_COUNT);
939+ for (i = 0; i < COUNT; i++) {
940+ IntVector_push_back(x, rand() % COUNT);
941941 }
942- assert(IntVector_size(x) == SEARCH_COUNT);
942+ assert(IntVector_size(x) == COUNT);
943943
944944 IntVector_sort(x, 0, IntVector_size(x) / 2, int_less);
945945 IntVector_sort(x, IntVector_size(x) / 2, IntVector_size(x) / 2, int_less);
@@ -946,7 +946,7 @@
946946 int prev;
947947
948948 prev = 0;
949- for (i = 0; i < SEARCH_COUNT / 2; i++) {
949+ for (i = 0; i < COUNT / 2; i++) {
950950 // printf("%d ", *IntVector_at(x, i));
951951 assert(*IntVector_at(x, i) >= prev);
952952 prev = *IntVector_at(x, i);
@@ -953,23 +953,23 @@
953953 }
954954 printf("\n");
955955 prev = 0;
956- for (i = 0; i < SEARCH_COUNT / 2; i++) {
957-// printf("%d ", *IntVector_at(x, i + SEARCH_COUNT / 2));
958- assert(*IntVector_at(x, i + SEARCH_COUNT / 2) >= prev);
959- prev = *IntVector_at(x, i + SEARCH_COUNT / 2);
956+ for (i = 0; i < COUNT / 2; i++) {
957+// printf("%d ", *IntVector_at(x, i + COUNT / 2));
958+ assert(*IntVector_at(x, i + COUNT / 2) >= prev);
959+ prev = *IntVector_at(x, i + COUNT / 2);
960960 }
961961 printf("\n");
962- assert(IntVector_size(x) == SEARCH_COUNT);
962+ assert(IntVector_size(x) == COUNT);
963963
964964 IntVector_inplace_merge(x, 0, IntVector_size(x) / 2, IntVector_size(x), int_less);
965965 prev = 0;
966- for (i = 0; i < SEARCH_COUNT; i++) {
966+ for (i = 0; i < COUNT; i++) {
967967 // printf("%d ", *IntVector_at(x, i));
968968 assert(*IntVector_at(x, i) >= prev);
969969 prev = *IntVector_at(x, i);
970970 }
971971 printf("\n");
972- assert(IntVector_size(x) == SEARCH_COUNT);
972+ assert(IntVector_size(x) == COUNT);
973973
974974 HEAP_RESET_FAIL_COUNT(&heap);
975975
@@ -982,51 +982,51 @@
982982 IntVector *x;
983983 int i;
984984 printf("***** test_5_3 *****\n");
985- x = IntVector_new(SEARCH_COUNT);
985+ x = IntVector_new(COUNT);
986986 assert(x);
987987 // inplace_merge
988- for (i = 0; i < SEARCH_COUNT; i++) {
988+ for (i = 0; i < COUNT; i++) {
989989 assert(IntVector_push_back(x, i));
990990 }
991- assert(IntVector_size(x) == SEARCH_COUNT);
991+ assert(IntVector_size(x) == COUNT);
992992
993993 IntVector_inplace_merge(x, 0, IntVector_size(x) / 2, IntVector_size(x), int_less);
994- for (i = 0; i < SEARCH_COUNT; i++) {
994+ for (i = 0; i < COUNT; i++) {
995995 assert(*IntVector_at(x, i) == i);
996996 }
997- assert(IntVector_size(x) == SEARCH_COUNT);
997+ assert(IntVector_size(x) == COUNT);
998998
999999 IntVector_inplace_merge(x, 0, IntVector_size(x), IntVector_size(x), int_less);
1000- for (i = 0; i < SEARCH_COUNT; i++) {
1000+ for (i = 0; i < COUNT; i++) {
10011001 assert(*IntVector_at(x, i) == i);
10021002 }
1003- assert(IntVector_size(x) == SEARCH_COUNT);
1003+ assert(IntVector_size(x) == COUNT);
10041004
10051005 IntVector_inplace_merge(x, 0, 0, IntVector_size(x), int_less);
1006- for (i = 0; i < SEARCH_COUNT; i++) {
1006+ for (i = 0; i < COUNT; i++) {
10071007 assert(*IntVector_at(x, i) == i);
10081008 }
1009- assert(IntVector_size(x) == SEARCH_COUNT);
1009+ assert(IntVector_size(x) == COUNT);
10101010
10111011 IntVector_inplace_merge(x, 0, 0, 0, int_less);
1012- for (i = 0; i < SEARCH_COUNT; i++) {
1012+ for (i = 0; i < COUNT; i++) {
10131013 assert(*IntVector_at(x, i) == i);
10141014 }
1015- assert(IntVector_size(x) == SEARCH_COUNT);
1015+ assert(IntVector_size(x) == COUNT);
10161016
10171017 IntVector_inplace_merge(x, IntVector_size(x), IntVector_size(x), IntVector_size(x), int_less);
1018- for (i = 0; i < SEARCH_COUNT; i++) {
1018+ for (i = 0; i < COUNT; i++) {
10191019 assert(*IntVector_at(x, i) == i);
10201020 }
1021- assert(IntVector_size(x) == SEARCH_COUNT);
1021+ assert(IntVector_size(x) == COUNT);
10221022
10231023 #ifdef MY_MALLOC
10241024 HEAP_SET_FAIL_COUNT(&heap, 0);
10251025 IntVector_inplace_merge(x, 0, IntVector_size(x) / 2, IntVector_size(x), int_less);
1026- for (i = 0; i < SEARCH_COUNT; i++) {
1026+ for (i = 0; i < COUNT; i++) {
10271027 assert(*IntVector_at(x, i) == i);
10281028 }
1029- assert(IntVector_size(x) == SEARCH_COUNT);
1029+ assert(IntVector_size(x) == COUNT);
10301030
10311031 HEAP_RESET_FAIL_COUNT(&heap);
10321032 #endif
@@ -1050,12 +1050,12 @@
10501050 IntVector *x;
10511051 int i;
10521052 printf("***** test_6_1 *****\n");
1053- x = IntVector_new(SEARCH_COUNT);
1053+ x = IntVector_new(COUNT);
10541054 assert(x);
1055- for (i = 0; i < SEARCH_COUNT; i++) {
1055+ for (i = 0; i < COUNT; i++) {
10561056 assert(IntVector_push_back(x, i));
10571057 }
1058- assert(IntVector_size(x) == SEARCH_COUNT);
1058+ assert(IntVector_size(x) == COUNT);
10591059 assert(!IntVector_is_heap(x, 0, IntVector_size(x), int_less));
10601060 // make_heap
10611061 IntVector_make_heap(x, 0, IntVector_size(x), int_less);
@@ -1062,7 +1062,7 @@
10621062 assert(IntVector_is_heap(x, 0, IntVector_size(x), int_less));
10631063 // sort_heap
10641064 IntVector_sort_heap(x, 0, IntVector_size(x), int_less);
1065- for (i = 0; i < SEARCH_COUNT; i++) {
1065+ for (i = 0; i < COUNT; i++) {
10661066 assert(*IntVector_at(x, i) == i);
10671067 }
10681068
@@ -1073,14 +1073,14 @@
10731073 assert(IntVector_is_heap(x, 0, IntVector_size(x), int_greater));
10741074 // sort_heap
10751075 IntVector_sort_heap(x, 0, IntVector_size(x), int_greater);
1076- for (i = 0; i < SEARCH_COUNT; i++) {
1077- assert(*IntVector_at(x, i) == SEARCH_COUNT - 1 - i);
1076+ for (i = 0; i < COUNT; i++) {
1077+ assert(*IntVector_at(x, i) == COUNT - 1 - i);
10781078 }
10791079
10801080 IntVector_sort(x, 0, IntVector_size(x), int_less);
10811081
10821082 // 途中から
1083- size_t half_size = SEARCH_COUNT / 2;
1083+ size_t half_size = COUNT / 2;
10841084 assert(!IntVector_is_heap(x, half_size, IntVector_size(x) - half_size, int_less));
10851085 // make_heap
10861086 IntVector_make_heap(x, half_size, IntVector_size(x) - half_size, int_less);
@@ -1088,7 +1088,7 @@
10881088 assert(IntVector_is_heap(x, half_size, IntVector_size(x) - half_size, int_less));
10891089 // sort_heap
10901090 IntVector_sort_heap(x, half_size, IntVector_size(x) - half_size, int_less);
1091- for (i = 0; i < SEARCH_COUNT; i++) {
1091+ for (i = 0; i < COUNT; i++) {
10921092 assert(*IntVector_at(x, i) == i);
10931093 }
10941094
@@ -1096,14 +1096,14 @@
10961096 int prev;
10971097 IntVector_clear(x);
10981098 srand(time(0));
1099- for (i = 0; i < SEARCH_COUNT; i++) {
1100- IntVector_push_back(x, rand() % SEARCH_COUNT);
1099+ for (i = 0; i < COUNT; i++) {
1100+ IntVector_push_back(x, rand() % COUNT);
11011101 }
1102- assert(IntVector_size(x) == SEARCH_COUNT);
1102+ assert(IntVector_size(x) == COUNT);
11031103 assert(!IntVector_is_heap(x, 0, IntVector_size(x), int_less));
11041104 // make_heap
11051105 IntVector_make_heap(x, 0, IntVector_size(x), int_less);
1106- for (i = 0; i < SEARCH_COUNT; i++) {
1106+ for (i = 0; i < COUNT; i++) {
11071107 // printf("%d ", *IntVector_at(x, i));
11081108 }
11091109 printf("\n");
@@ -1111,7 +1111,7 @@
11111111 // sort_heap
11121112 IntVector_sort_heap(x, 0, IntVector_size(x), int_less);
11131113 prev = 0;
1114- for (i = 0; i < SEARCH_COUNT; i++) {
1114+ for (i = 0; i < COUNT; i++) {
11151115 // printf("%d ", *IntVector_at(x, i));
11161116 assert(*IntVector_at(x, i) >= prev);
11171117 prev = *IntVector_at(x, i);
@@ -1119,14 +1119,14 @@
11191119 printf("\n");
11201120
11211121 IntVector_clear(x);
1122- for (i = 0; i < SEARCH_COUNT; i++) {
1123- IntVector_push_back(x, rand() % SEARCH_COUNT);
1122+ for (i = 0; i < COUNT; i++) {
1123+ IntVector_push_back(x, rand() % COUNT);
11241124 }
1125- assert(IntVector_size(x) == SEARCH_COUNT);
1125+ assert(IntVector_size(x) == COUNT);
11261126 assert(!IntVector_is_heap(x, 0, IntVector_size(x), int_greater));
11271127 // make_heap
11281128 IntVector_make_heap(x, 0, IntVector_size(x), int_greater);
1129- for (i = 0; i < SEARCH_COUNT; i++) {
1129+ for (i = 0; i < COUNT; i++) {
11301130 // printf("%d ", *IntVector_at(x, i));
11311131 }
11321132 printf("\n");
@@ -1133,8 +1133,8 @@
11331133 assert(IntVector_is_heap(x, 0, IntVector_size(x), int_greater));
11341134 // sort_heap
11351135 IntVector_sort_heap(x, 0, IntVector_size(x), int_greater);
1136- prev = SEARCH_COUNT;
1137- for (i = 0; i < SEARCH_COUNT; i++) {
1136+ prev = COUNT;
1137+ for (i = 0; i < COUNT; i++) {
11381138 // printf("%d ", *IntVector_at(x, i));
11391139 assert(*IntVector_at(x, i) <= prev);
11401140 prev = *IntVector_at(x, i);
@@ -1148,21 +1148,21 @@
11481148 IntVector *x;
11491149 int i;
11501150 printf("***** test_6_2 *****\n");
1151- x = IntVector_new(SEARCH_COUNT);
1151+ x = IntVector_new(COUNT);
11521152 assert(x);
1153- for (i = 0; i < SEARCH_COUNT; i++) {
1153+ for (i = 0; i < COUNT; i++) {
11541154 assert(IntVector_push_back(x, i));
11551155 }
1156- assert(IntVector_size(x) == SEARCH_COUNT);
1156+ assert(IntVector_size(x) == COUNT);
11571157
11581158 // push_heap
1159- for (i = 1; i <= SEARCH_COUNT; i++) {
1159+ for (i = 1; i <= COUNT; i++) {
11601160 IntVector_push_heap(x, 0, i, int_less);
11611161 assert(IntVector_is_heap(x, 0, i, int_less));
11621162 }
11631163 assert(IntVector_is_heap(x, 0, IntVector_size(x), int_less));
11641164 // pop_heap
1165- for (i = SEARCH_COUNT; i > 0; i--) {
1165+ for (i = COUNT; i > 0; i--) {
11661166 IntVector_pop_heap(x, 0, i, int_less);
11671167 assert(IntVector_is_heap(x, 0, i - 1, int_less));
11681168 assert(*IntVector_at(x, i - 1) == i - 1);
@@ -1173,16 +1173,16 @@
11731173 IntVector_sort(x, 0, IntVector_size(x), int_greater);
11741174 assert(!IntVector_is_heap(x, 0, IntVector_size(x), int_greater));
11751175 // push_heap
1176- for (i = 1; i <= SEARCH_COUNT; i++) {
1176+ for (i = 1; i <= COUNT; i++) {
11771177 IntVector_push_heap(x, 0, i, int_greater);
11781178 assert(IntVector_is_heap(x, 0, i, int_greater));
11791179 }
11801180 assert(IntVector_is_heap(x, 0, IntVector_size(x), int_greater));
11811181 // pop_heap
1182- for (i = SEARCH_COUNT; i > 0; i--) {
1182+ for (i = COUNT; i > 0; i--) {
11831183 IntVector_pop_heap(x, 0, i, int_greater);
11841184 assert(IntVector_is_heap(x, 0, i - 1, int_greater));
1185- assert(*IntVector_at(x, i - 1) == SEARCH_COUNT - i);
1185+ assert(*IntVector_at(x, i - 1) == COUNT - i);
11861186 // printf("%d\n", *IntVector_at(x, i - 1));
11871187 }
11881188 assert(!IntVector_is_heap(x, 0, IntVector_size(x), int_greater));
@@ -1191,20 +1191,20 @@
11911191 int prev;
11921192 IntVector_clear(x);
11931193 srand(time(0));
1194- for (i = 0; i < SEARCH_COUNT; i++) {
1195- IntVector_push_back(x, rand() % SEARCH_COUNT);
1194+ for (i = 0; i < COUNT; i++) {
1195+ IntVector_push_back(x, rand() % COUNT);
11961196 }
1197- assert(IntVector_size(x) == SEARCH_COUNT);
1197+ assert(IntVector_size(x) == COUNT);
11981198 assert(!IntVector_is_heap(x, 0, IntVector_size(x), int_less));
11991199 // push_heap
1200- for (i = 1; i <= SEARCH_COUNT; i++) {
1200+ for (i = 1; i <= COUNT; i++) {
12011201 IntVector_push_heap(x, 0, i, int_less);
12021202 assert(IntVector_is_heap(x, 0, i, int_less));
12031203 }
12041204 assert(IntVector_is_heap(x, 0, IntVector_size(x), int_less));
12051205 // pop_heap
1206- prev = SEARCH_COUNT;
1207- for (i = SEARCH_COUNT; i > 0; i--) {
1206+ prev = COUNT;
1207+ for (i = COUNT; i > 0; i--) {
12081208 IntVector_pop_heap(x, 0, i, int_less);
12091209 assert(IntVector_is_heap(x, 0, i - 1, int_less));
12101210 assert(*IntVector_at(x, i - 1) <= prev);
@@ -1215,13 +1215,13 @@
12151215
12161216 IntVector_clear(x);
12171217 srand(time(0));
1218- for (i = 0; i < SEARCH_COUNT; i++) {
1219- IntVector_push_back(x, rand() % SEARCH_COUNT);
1218+ for (i = 0; i < COUNT; i++) {
1219+ IntVector_push_back(x, rand() % COUNT);
12201220 }
1221- assert(IntVector_size(x) == SEARCH_COUNT);
1221+ assert(IntVector_size(x) == COUNT);
12221222 assert(!IntVector_is_heap(x, 0, IntVector_size(x), int_greater));
12231223 // push_heap
1224- for (i = 1; i <= SEARCH_COUNT; i++) {
1224+ for (i = 1; i <= COUNT; i++) {
12251225 IntVector_push_heap(x, 0, i, int_greater);
12261226 assert(IntVector_is_heap(x, 0, i, int_greater));
12271227 }
@@ -1228,7 +1228,7 @@
12281228 assert(IntVector_is_heap(x, 0, IntVector_size(x), int_greater));
12291229 // pop_heap
12301230 prev = 0;
1231- for (i = SEARCH_COUNT; i > 0; i--) {
1231+ for (i = COUNT; i > 0; i--) {
12321232 IntVector_pop_heap(x, 0, i, int_greater);
12331233 assert(IntVector_is_heap(x, 0, i - 1, int_greater));
12341234 assert(*IntVector_at(x, i - 1) >= prev);
--- trunk/README.txt (revision 192)
+++ trunk/README.txt (revision 193)
@@ -25,7 +25,7 @@
2525 CSTL.html CSTL.rdをhtml化したもの(tarballのみに同梱)
2626 Makefile CSTL.htmlを生成するためのMakefile
2727 test/ 単体テスト
28- sample/ CSTLを使用したサンプル
28+ sample/ CSTLを使用したサンプルやSTLと性能を比較したベンチマーク
2929 README.txt このファイル
3030
3131
Show on old repository browser