From 179607bdfe9ea36cf5325a10ee8b7edb1f834147 Mon Sep 17 00:00:00 2001 From: hackprot1 <91518230+hackprot1@users.noreply.github.com> Date: Sat, 2 Oct 2021 23:30:04 +0530 Subject: [PATCH 1/3] Merge sort README in Haskell --- merge-sort.hs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 merge-sort.hs diff --git a/merge-sort.hs b/merge-sort.hs new file mode 100644 index 00000000..8bcb192d --- /dev/null +++ b/merge-sort.hs @@ -0,0 +1,27 @@ +-- # Binary Search in Haskell +-- This is an implementation of simple Binary Search in Haskell on any type that can be ordered. +-- Binary Search is an effective searching algorithm, that can be used to find an element in a sorted list in O(lg(n)) time. + +-- Binary search with index carry +bsWithIndex :: (Ord a) => [a] -> a -> Int -> Maybe Int +bsWithIndex list n i + | n == head list = Just i + | len == 1 = Nothing -- only candidate in list is not the right elem + | n < head ys = bsWithIndex xs n i + | otherwise = bsWithIndex ys n (i + half) + where + len = length list + half = len `div` 2 + (xs, ys) = splitAt half list + +-- Binary search returning index, or -1 if element not in list +bs :: (Ord a) => [a] -> a -> Int +bs list n = case bsWithIndex list n 0 of + Just x -> x + Nothing -> -1 + +main :: IO () +main = do + let intList = [1,4,7,10,25,30] + print $ bs intList 29 -- 29 -> -1 as not in list + print $ bs intList 7 -- 7 -> 2 as in list From 6b477052acf7a2e9cf7e48dc97069b4743406895 Mon Sep 17 00:00:00 2001 From: hackprot2 <91518287+hackprot2@users.noreply.github.com> Date: Sat, 2 Oct 2021 23:54:51 +0530 Subject: [PATCH 2/3] Contributing rules for Japanese devs --- CONTRIBUTING_JAP.md | 79 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 CONTRIBUTING_JAP.md diff --git a/CONTRIBUTING_JAP.md b/CONTRIBUTING_JAP.md new file mode 100644 index 00000000..b236c167 --- /dev/null +++ b/CONTRIBUTING_JAP.md @@ -0,0 +1,79 @@ +#貢献 + +このプロジェクトに貢献するためには、次のとおりです。 + + - バグを報告する + - コードの現在の状態について議論する + - 修正提出する + - 新機能の提案する + - 管理者になる + + +##貢献のためのコース + +*あなたが作業する問題について言及します。他の人に作業する案件が割り当てられていないことを確認するようにします。 + +*もしアルゴリズムが足りないと思われる場合は、問題を作成します。 + +### Pull Request作成 + +> - PRを作ろうとする課題に割り当てられていることを確認します。 +> - もし割り当てられる前にPRを作成する場合には、 `invalid(無効)`で表示され、マージされずに終了します。 + +*ストアをフォークして、あなたのコンピュータにコピーします。 +*コピーされたストレージのメインbranchにupstream linkをよりしてください。 + `` ` + git remote add upstream https://github.com/div-bargali/Data-Structures-and-Algorithms.git + `` ` +* Upstreamから取得Cloneストアを最新の状態に維持します。 (この操作は、新しい変更をコミット中にマージの競合を防ぐこともできます)。 + `` ` + git pull upstream main https://github.com/div-bargali/Data-Structures-and-Algorithms.git + `` ` +*あなたのfeature branchを作りなさい。 + `` ` + git checkout -b + `` ` +*すべての変更にコミットしてください。 + `` ` + git commit -m "Meaningful commit message" + `` ` +*レビューのために変更をpushしてください。 + `` ` + git push origin + `` ` + +* GitHubのプロジェクトのリポジトリにPRを作成します。 + +###その他の注意事項 + +*コードは、読みやすさのために適切に作成する必要があります。 +*もしテストが必要なコードを追加する場合は、コメントにtestsを追加できます。 +* Pythonの場合は、テストを提供するためにdocstringsを使用します。 +*あなたのコードが正しくフォーマットされていることを確認してください。 +*適切なディレクトリ構造を維持していることを確認してください: + `` ` + / / / <。 。 > + `` ` + `` ` + / / / <。 。 > + `` ` +*このPull requestを問題化してください! + +##問題提起/バグを報告する + +問題を作成するときに、すでに提示されたことがないことを確認します。さらに変更について適切な説明を提供しています。 +もしいくつかのコードの改善事項について提示する場合には、その改善点の詳細を提示(提供)してください。 + +**大きい問題製の**は、以下の事項を持っている必要があります: + + - 変更の迅速な要約 + - 再処理の過程で生ずるもバグについて + - 具体的これ! + - 可能な場合、サンプルコードを提供する。 + - 予想日(問題) + - 実際に発生した日(問題) + - メモ(おそらくあなたがこれが起こるだろうと思ったことを含むか、試みたが、動作していないこと) + +##参考 + +この文書は、[フェイスブックのDraft(ドラフト)](https://github.com/facebook/draft-js/blob/a9316a723f9e918afde44dea68b5f9f39b7d9b00/CONTRIBUTING.md)のオープンソースの貢献ガイドラインから適用された。 From 645402a08280e0efc323ffdf7056b6bbf9cb91f8 Mon Sep 17 00:00:00 2001 From: GothamK <43772245+GothamK@users.noreply.github.com> Date: Thu, 14 Oct 2021 21:19:48 +0530 Subject: [PATCH 3/3] Implementation of LRU cache --- C++/Data-Structures/LinkedList/LRU_cache | 80 ++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 C++/Data-Structures/LinkedList/LRU_cache diff --git a/C++/Data-Structures/LinkedList/LRU_cache b/C++/Data-Structures/LinkedList/LRU_cache new file mode 100644 index 00000000..dd769b8a --- /dev/null +++ b/C++/Data-Structures/LinkedList/LRU_cache @@ -0,0 +1,80 @@ +// This can be optimized by storing a reference (iterator) to each key in a hash map. + +#include +using namespace std; + +class LRUCache { + // store keys of cache + list dq; + + // store references of key in cache + unordered_map::iterator> ma; + int csize; // maximum capacity of cache + +public: + LRUCache(int); + void refer(int); + void display(); +}; + +// Declare the size +LRUCache::LRUCache(int n) +{ + csize = n; +} + +// Refers key x with in the LRU cache +void LRUCache::refer(int x) +{ + // not present in cache + if (ma.find(x) == ma.end()) { + // cache is full + if (dq.size() == csize) { + // delete least recently used element + int last = dq.back(); + + // Pops the last elmeent + dq.pop_back(); + + // Erase the last + ma.erase(last); + } + } + + // present in cache + else + dq.erase(ma[x]); + + // update reference + dq.push_front(x); + ma[x] = dq.begin(); +} + +// Function to display contents of cache +void LRUCache::display() +{ + + // Iterate in the deque and print + // all the elements in it + for (auto it = dq.begin(); it != dq.end(); + it++) + cout << (*it) << " "; + + cout << endl; +} + +// Driver Code +int main() +{ + LRUCache ca(4); + + ca.refer(1); + ca.refer(2); + ca.refer(3); + ca.refer(1); + ca.refer(4); + ca.refer(5); + ca.display(); + + return 0; +}